1. Initialize the database;
Postgresql-setup Initdb
2. Start PostgreSQL and set it to boot;
Systemctl Restart PostgreSQL
Systemctl Enable PostgreSQL
3. Log in to the database to see the status;
Su-postgres
Psql
\du (View roles)
\l (List all databases)
\q (Exit)
4. Create a role (user in PostgreSQL) and a DB instance;
Su-postgres
CreateUser Dbuser
CREATEDB-E-O dbuser dbname
5. Set a password for the new user
Su-postgres
Psql
\password dbuser (enter password two times)
Vim/var/lib/pgsql/data/pg_hba.conf
In/var/lib/pgsql/data/pg_hba.conf, the default validation method
Host all 127.0.0.1/32 ident
Change to password verification
Host All 127.0.0.1/32 MD5
6. Restart the database for new authentication methods to take effect
Systemctl Restart PostgreSQL
7. New User login database;
Psql-u dbuser-d dbname-h 127.0.0.1 (enter the previous password)
8. Experience (the following operations are in the PostgreSQL terminal)
\DP (view the table in the current library)
CREATE TABLE test1 (t1 int, T2 varchar (20));
\dp
\d test1 (view table structure)
SELECT * from Test1 limit 10;
Insert into test1 (T1,T2) VALUES (one, ' CCCCC '), (+, ' aaaa ');
SELECT * from Test1 limit 10;
TRUNCATE TABLE test1;
SELECT * from Test1 limit 10;
drop table test1;
SELECT * from Test1 limit 10;
\dp
PostgreSQL initialization for CENTOS7