一 安装环境准备
安装环境:Centos7
安装包:postgresql-10.17-1-linux-x64-binaries.tar.gz
下载链接:https://www.enterprisedb.com/download-postgresql-binaries
复制代码
二 解压文件
上传至/home目录解压
[root@localhost home]# tar -xvzf postgresql-10.1-1-linux-x64-binaries.tar.gz
复制代码
三 创建安装目录
在/opt目录下新建postgresql,将解压文件放入,并新建data文件夹
[root@localhost home]# cd /opt
[root@localhost opt]# mkdir postgresql
[root@localhost home]# mv /home/pgsql/ postgresql/
[root@localhost home]# cd postgresql
[root@localhost postgresql]# mkdir data
复制代码
四 创建用户
创建postgres用户操作数据库
[root@localhost postgresql]# useradd postgres
[root@localhost postgresql]# passwd postgres
复制代码
方便操作,改成无密码切换
[root@localhost postgresql]# passwd -d postgres
复制代码
五 修改目录权限
[root@localhost postgresql]# cd /opt
[root@localhost opt]# chown -R postgres:postgres postgresql/
复制代码
六 初始化数据库
[root@localhost opt]# su postgres
[postgres@localhost opt]$ cd postgresql/
[postgres@localhost postgresql]$ ./pgsql/bin/initdb -D data/
复制代码
七 配置远程访问
修改/opt/postgresql/data目录下面postgresql.conf、pg_hba.conf文件
# postgresql.conf
将listen_addresses='localhost'修改为listen_addresses='*'
复制代码
# pg_hba.conf
在文件添加 host all all 0.0.0.0/0 md5
复制代码
八 启动服务
[postgres@localhost postgresql]$ ./pgsql/bin/pg_ctl -D data/ -l logfile start
复制代码
九 登录后台
[postgres@localhost postgresql]$ cd pgsql/bin/
[postgres@localhost bin]$ ./psql -h 127.0.0.1 -U postgres
psql.bin (10.17)
Type "help" for help.
postgres=# alter user postgres with password 'postgres';
ALTER ROLE
复制代码
十 远程访问
十一 命令行总结
切到/opt/postgresql/pgsql/bin目录下
开启服务:./pg_ctl -D ../../data/ -l logfile start
关闭服务:./pg_ctl -D ../../data/ -l logfile stop
重启服务:./pg_ctl -D ../../data/ -l logfile restart
进程查看:ps -ef | grep postgres
登录后台:./psql -h 127.0.0.1 -U postgres
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END