Initialize PostgreSQL in CentOS7

Source: Internet
Author: User
Tags postgresql terminal

Initialize PostgreSQL in CentOS7

1. Install epel;

Rpm-ivh http://mirrors.hustunique.com/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm

Or

Yum install epel-release

2. Install postgresql;

Yum install postgresql *

3. initialize the database;

Postgresql-setup initdb

4. Start postgresql and set it to start automatically;

Systemctl restart sqlsystemctl enable postgresql

5. log on to the database to check the status. (Omitted)

Su-role spsql \ du (view role) \ l (list all databases) \ q (Exit)

6. Create roles (users in postgresql) and database instances;

Su-postgrescreateuser dbusercreatedb-e-O dbuser dbname

7. Set a password for a new user

Su-javasspsql \ password dbuser (enter the password twice) vim/var/lib/pgsql/data/pg_assist.conf

In/var/lib/pgsql/data/pg_cmd.conf, the default verification method is used.

Hostall all 127.0.0.1/32 ident

Change to password verification

Hostall all 127.0.0.1/32md5

8. Restart the database to make the new verification method take effect.

Systemctl restart postgresql

9. log on to the database as a new user;

Psql-U dbuser-d dbname-h 127.0.0.1 (enter the previous password)

10. Play (the following operations are performed on the postgresql Terminal)

\ Dp (View tables in the current database) 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 (11, 'ccccc '), (22, 'aaa'); select * from test1 limit 10; truncate table test1; select * from test1 limit 10; drop table test1; select * from test1 limit 10; \ dp

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.