redhat7.5安装postgresql
一、检查是否已安装postgresql
点击查看代码
[root@cmc ~]# rpm -qa |grep postgres
[root@cmc ~]#
二、关闭防火墙和selinux
点击查看代码
[root@cmc pgbase]# systemctl stop firewalld
[root@cmc pgbase]# systemctl disable firewalld
[root@cmc pgbase]# vi /etc/selinux/config
[root@cmc pgbase]# cat /etc/selinux/config
SELINUX=disabled
三、创建用户和目录
点击查看代码
[root@cmc ~]# useradd postgres
[root@cmc ~]# mkdir -p /pgbase
[root@cmc ~]# mkdir -p /pgdata
[root@cmc ~]# chown -R postgres:postgres /pgbase/
[root@cmc ~]# chown -R postgres:postgres /pgdata/
四、解压postgresql安装包
点击查看代码
[root@cmc ~]# tar -xvf postgresql-12.10.tar.gz
五、补充安装一下依赖包
点击查看代码
[root@cmc postgresql-12.10]# yum install -y gcc
[root@cmc postgresql-12.10]# yum install -y readline-devel
[root@cmc postgresql-12.10]# yum install -y zlib-devel
六、编译postgresql到pgbase目录
点击查看代码
[root@cmc ~]# cd postgresql-12.10/
[root@cmc postgresql-12.10]# ./configure --prefix=/pgbase
[root@cmc postgresql-12.10]# make
[root@cmc postgresql-12.10]# make install
七、查看安装目录是否正常
点击查看代码
[root@cmc pgbase]# ll
total 12
drwxr-xr-x. 2 root root 4096 Mar 26 15:29 bin
drwxr-xr-x. 4 root root 4096 Mar 26 15:29 include
drwxr-xr-x. 4 root root 4096 Mar 26 15:29 lib
drwxr-xr-x. 3 root root 24 Mar 26 15:29 share
<br>
[root@cmc ~]# chown -R postgres:postgres /pgbase/
八、配置环境变量
点击查看代码
[postgres@cmc ~]$ vi .bash_profile
[postgres@cmc ~]$ source .bash_profile
[postgres@cmc ~]$ cat .bash_profile
export PATH=$PATH:$HOME/.local/bin:$HOME/bin:/pgbase/bin
export PGDATA=/pgdata
九、初始化db
点击查看代码
[postgres@cmc ~]$ initdb -D $PGDATA
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.
The database cluster will be initialized with locale "en_US.UTF-8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".
Data page checksums are disabled.
fixing permissions on existing directory /pgdata ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok
initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
pg_ctl -D /pgdata -l logfile start
十、启动pg
点击查看代码
[postgres@cmc ~]$ pg_ctl -D /pgdata -l logfile start
waiting for server to start.... done
server started
[postgres@cmc ~]$ ps -ef|grep postgres
postgres 13444 1 0 15:43 ? 00:00:00 /pgbase/bin/postgres -D /pgdata
postgres 13446 13444 0 15:43 ? 00:00:00 postgres: checkpointer
postgres 13447 13444 0 15:43 ? 00:00:00 postgres: background writer
postgres 13448 13444 0 15:43 ? 00:00:00 postgres: walwriter
postgres 13449 13444 0 15:43 ? 00:00:00 postgres: autovacuum launcher
postgres 13450 13444 0 15:43 ? 00:00:00 postgres: stats collector
postgres 13451 13444 0 15:43 ? 00:00:00 postgres: logical replication launcher
十一、正常登录
点击查看代码
[postgres@cmc ~]$ psql
psql (12.10)
Type "help" for help.
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=#
十二、关闭pg
点击查看代码
[postgres@cmc ~]$ pg_ctl -D /pgdata stop -m fast
waiting for server to shut down.... done
server stopped
以上。

浙公网安备 33010602011771号