一、安裝
可以參考postgresql官網安裝教程:https://www.postgresql.org/download/linux/redhat/
Centos 6 安裝postgresql 10
添加RPM:
-- centos 6 安裝 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 安裝 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
二、創建用戶和數據庫
# su - postgres -- 首先切換到postgres -bash-4.1$ psql -- 輸入psql psql (10.5) Type "help" for help. postgres=#
創建用戶
postgres=# create user username with password '****'; CREATE ROLE postgres=#
需要注意:
1. 要以英文分號結尾
2.密碼需要引號包裹
創建數據庫
postgres=# create database dbtest owner username; -- 創建數據庫指定所屬者 CREATE DATABASE postgres=#
將數據庫得權限,全部賦給某個用戶
postgres=# grant all on database dbtest to username; -- 將dbtest所有權限賦值給username GRANT postgres=#
三、數據庫的導入導出
導入整個數據庫
psql -U username databasename < /data/dum.sql -- 用戶名和數據庫名