PostgreSQL Install and create users and create a database

One. Installation

You can refer to the postgresql official website installation tutorial: https://www.postgresql.org/download/linux/redhat/

Centos 6 install postgresql 10

Add RPM:

-- centos 6 install postgresql 10

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm

-- Centos 7 install postgresql 10
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

Install the client:

yum install postgresql10

Install the server:

yum install postgresql10-server

Start data and initialize:

service postgresql-10 initdb

chkconfig postgresql-10 on
service postgresql-10 start

Second, create users and databases

copy code
# su-postgres - First switch to postgres


-bash-4.1$ psql - Enter psql
psql (10.5)
Type "help" for help.

postgres=#
copy code

Create user

postgres=# create user username with password'*** *';

CREATE ROLE
postgres=#

Note:

  1. It must end with an English semicolon

  2. The password needs to be wrapped in quotation marks< /p>

Create a database

postgres=# create database dbtest owner username; - Create a database to specify the owner

CREATE DATABASE
postgres=#

Grant all database permissions to a user

postgres=# grant all on database dbtest to username; - Assign all permissions of dbtest to username

GRANT
postgres=#

3. Import and export of the database

Import the entire database

psql -U username databasename 

-- centos 6 install postgresql 10

yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-6-x86_64/pgdg-centos10-10-2.noarch.rpm

-- Centos 7 install postgresql 10
yum install https://download.postgresql.org/pub/repos/yum/10/redhat/rhel-7-x86_64/pgdg-centos10-10-2.noarch.rpm

yum install postgresql10

yum install postgresql10-server

service postgresql-10 initdb

chkconfig postgresql-10 on
service postgresql-10 start

copy code
# su-postgres - first switch to postgres


-bash-4.1$ psql - Enter psql
psql (10.5)
Type "help" for help.

postgres=#
copy code

copy code

copy code

postgres=# create user username with password'****';

CREATE ROLE
postgres=#

postgres=# create database dbtest owner username; - create database to specify the owner

CREATE DATABASE
postgres=#

postgres=# grant all on database dbtest to username; - Assign all permissions of dbtest to username

GRANT
postgres=#

psql -U username databasename 

Leave a Comment

Your email address will not be published.