安装流程 | |
1.安装上传的文件的插件 | |
命令: | yum -y install lrzsz |
1、解压安装包(postgresql-13.1.tar.gz) | |
命令 | mkdir /usr/local/postgresql |
命令 | tar -zxvf postgresql-13.1.tar.gz -C /usr/local/postgresql/ |
2、查询压缩文件 | |
命令 | cd /usr/local/postgresql/ |
3、编译文件(postgresql) | |
命令 | [root@host-003 postgresql]# cd postgresql-13.1/ |
命令 | ./configure --prefix=/usr/local/postgresql |
[root@host-003 postgresql-13.1]# ./configure --prefix=/usr/local/postgresql | |
出现安装错误【onfigure: error: readline library not found】 | |
命令 | yum install readline-devel |
出现安装错误【configure: error: zlib library not found】 | |
命令 | yum install zlib-devel |
出现安装错误【checking for DocBook XML V4.5..】 | |
命令 | yum install docbook-dtds docbook-style-xsl fop libxslt -y |
命令 | yum install readline-devel.x86_64 zlib-devel.x86_64 -y |
4、安装(postgresql) | |
命令 | make && make install |
[root@host-003 postgresql-13.1]# make && make install |
5、查阅安装情况 | |
命令 | cd /usr/local/postgresql/ |
6、创建目录 data、log | |
命令 | mkdir /usr/local/postgresql/{data,log} |
[root@host-003 postgresql]# mkdir /usr/local/postgresql/{data,log} |
7、加入系统环境变量 | |
命令 | vim /etc/profile |
[root@host-003 postgresql]# vim /etc/profile |
8、环境配置 | |
export PGHOME=/usr/local/postgresql export PGDATA=/usr/local/postgresql/data export PATH=$PATH:$PGHOME/bin | |
命令 | source /etc/profile |
[root@host-003 postgresql]# source /etc/profile |
export PGHOME=/usr/local/postgresql export PGDATA=/usr/local/postgresql/data export PATH=$PATH:$PGHOME/bin
9、增加用户 postgres 并赋权 | |
命令 | useradd postgres |
[root@host-003 postgresql]# useradd postgres | |
命令 | chown -R postgres:root /usr/local/postgresql |
[root@host-003 postgresql]# chown -R postgres:root /usr/local/postgresql |
10、初始化数据库(需要在用户【postgres】下执行,不能在【root】下执行) | |
切换用户: | |
命令 | su postgres |
[root@host-003 postgresql]# su postgres | |
初始化数据库: | |
命令 | /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/ |
[postgres@host-003 postgresql]$ /usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/ |
11、编辑配置文件(需要在用户【postgres】下执行,不能在【root】下执行) | |
编辑配置文件: | |
命令 | vim /usr/local/postgresql/data/postgresql.conf |
[postgres@host-003 postgresql]$ vim /usr/local/postgresql/data/postgresql.conf | |
配置文件 | |
listen_addresses = '*' | |
port = 5432 | |
命令 | vim /usr/local/postgresql/data/pg_hba.conf |
[postgres@host-003 postgresql]$ vim /usr/local/postgresql/data/pg_hba.conf | |
配置文件 | |
host all all 0.0.0.0/0 trust |
说明: | |
TYPE: | pg的连接方式,local:本地unix套接字,host:tcp/ip连接 |
DATABASE | 指定数据库 |
USER | 指定数据库用户 |
ADDRESS | ip地址,可以定义某台主机或某个网段,32代表检查整个ip地址,相当于固定的ip,24代表只检查前三位,最后一 位是0~255之间的任何一个 |
METHOD | 认证方式,常用的有ident,md5,password,trust,reject。 md5是常用的密码认证方式。 password是以明文密码传送给数据库,建议不要在生产环境中使用。 trust是只要知道数据库用户名就能登录,建议不要在生产环境中使用。 reject是拒绝认证。 |
12、启动服务(在用户【postgres】下执行) | |
命令 | pg_ctl start -l /usr/local/postgresql/log/pg_server.log |
[postgres@host-003 postgresql]$ pg_ctl start -l /usr/local/postgresql/log/pg_server.log | |
启动的时候【pg_server.log】不存在,需要自己指定 | |
命令 | netstat -nptl |
13、查看版本 | |
命令 | psql -V |
[postgres@host-003 postgresql]$ psql -V |
14、链接数据库 | |
命令 | psql -U postgres -d postgres |
[postgres@host-003 postgresql]$ psql -U postgres -d postgres |
15、设置用户信息 | |
命令 | CREATE USER ppsps_admin WITH PASSWORD 'admin'; |
命令 | CREATE USER nx_gf02 WITH PASSWORD '123456'; |
16、设置用户权限表 | |
命令 | GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO xxx |
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO nx_gf02; | |
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO ppsps_admin ; |