Table of contents
3. postgres installation and login
3.3.2. Modify postgres user password
4.1, PostgreSQL create database
1. The concept of postgresql
PostgreSQL is a free object-relational database server (ORDBMS), released under the flexible BSD license.
PostgreSQL developers pronounce it post-gress-QL.
PostgreSQL's Slogan is "the world's most advanced open source relational database".
Two, PostgreSQL features
-
Function : Through the function, the instruction program can be executed on the database server side.
-
Index : Users can customize the index method, or use the built-in B-tree, hash table and GiST index.
-
Trigger : A trigger is an event triggered by an SQL statement query. For example: An INSERT statement may trigger a trigger that checks data integrity. Triggers are usually fired by INSERT or UPDATE statements. Multiversion concurrency control: PostgreSQL uses a multiversion concurrency control (MVCC, Multiversion concurrency control) system for concurrency control. This system provides each user with a "snapshot" of the database. Every modification made by a user within a transaction is invisible to other users until the transaction is successfully committed.
-
Rules : Rules (RULE) allow a query to be rewritten, and are usually used to implement operations on views (VIEW), such as insert (INSERT), update (UPDATE), and delete (DELETE).
-
Data types : including text, arbitrary precision numeric arrays, JSON data, enumerated types, XML data
wait. -
Full-text search : via Tsearch2 or OpenFTS, Tsearch2 is embedded in version 8.3.
-
NoSQL : JSON, JSONB, XML, native support for HStore, foreign data wrappers to NoSQL databases.
-
Data Warehouse : Can smoothly migrate to GreenPlum, DeepGreen, HAWK, etc. that belong to the PostgreSQL ecosystem, and use FDW for ETL.
3. postgres installation and login
3.1, postgres installation
1. Install the postgres source
yum install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
2. Install the client
yum install postgresql11
3. Install the server
yum install postgresql11-server
4. Start up automatically
systemctl enable postgresql-11
systemctl start postgresql-11
3.2, postgres use
3.3.1, postgres login
By default, after PostgreSQL is installed, it comes with a command line tool SQL Shell (psql) .
The Linux system can directly switch to the postgres user to start the command line tool:
# are postgres
3.3.2. Modify postgres user password
#修改密码
alter user postgres with password 'xxx';
4. PostgreSQL command
4.1, PostgreSQL create database
CREATE DATABASE creates a database
The CREATE DATABASE command needs to be executed in the PostgreSQL command window, and the syntax format is as follows:
CREATE DATABASE dbname;
4.2, delete the database
PostgreSQL can delete a database in the following three ways:
- 1. Use the DROP DATABASE SQL statement to delete.
- 2. Use the dropdb command to delete.
- 3. Use the pgAdmin tool.
DROP DATABASE [ IF EXISTS ] name
4.3. Create a table
The CREATE TABLE syntax format is as follows:
CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY(one or more columns) );
CREATE TABLE is a keyword used to tell the database system that a data table will be created.
Table names must be unique among other table, sequence, index, view, or foreign table names in the same schema.
CREATE TABLE creates a new blank table in the current database, which will be owned by the user who issued this command.
Each field in the table defines a data type, as follows:
example
A table is created below, the table name is stu table, the primary key is ID , and NOT NULL means that the field does not allow NULL values:
We can use the \d command to see if the table was created successfully:
\d tablename View table information:
4.4. Delete table
DROP TABLE table_name;