PostgreSQL initialization for CENTOS7

Source: Internet
Author: User
Tags psql postgresql terminal

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.