postgresql源码安装

举报
snowofsummer 发表于 2021/10/12 09:00:27 2021/10/12
【摘要】 系统版本:[root@VM-16-10-centos start-scripts]# cat /etc/redhat-releaseCentOS Linux release 7.5.1804 (Core)软件下载:wget https://ftp.postgresql.org/pub/source/v13.4/postgresql-13.4.tar.gz依赖包安装:yum install -...

系统版本:

[root@VM-16-10-centos start-scripts]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

软件下载:

wget https://ftp.postgresql.org/pub/source/v13.4/postgresql-13.4.tar.gz

依赖包安装:

yum install -y readline
yum install -y readline-devel
yum install -y zlib
yum install -y zlib-devel

新建用户和设置环境变量:

groupadd postgres
useradd -g postgres postgres
#环境变量设置
export PATH=$PATH:/usr/local/postgresql/bin

解压并安装:

#此过程时间稍长。。。。。

tar xvf postgresql-13.4.tar.gz
./configure --prefix=/usr/local/postgresql
make && make install

配置数据文件位置初始化数据库:

mkdir -p /data/db01
chown -R postgres.postgres /data/db01
su - postgres
initdb -D  /data/db01、

##########
-bash-4.2$ initdb -D  /data/db01
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.utf8".
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 /data/db01 ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
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 /data/db01 -l logfile start

#启动数据库

-bash-4.2$ pg_ctl -D /data/db01   start
waiting for server to start....2021-10-12 08:48:12.553 CST [12010] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39), 64-bit
2021-10-12 08:48:12.554 CST [12010] LOG:  listening on IPv6 address "::1", port 5432
2021-10-12 08:48:12.554 CST [12010] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2021-10-12 08:48:12.593 CST [12010] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2021-10-12 08:48:12.627 CST [12021] LOG:  database system was shut down at 2021-10-12 08:47:57 CST
2021-10-12 08:48:12.640 CST [12010] LOG:  database system is ready to accept connections
 done
server started

#连接数据库

-bash-4.2$ psql
psql (13.4)
Type "help" for help.

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 |
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
(3 rows)

postgres=#

#停止数据库

-bash-4.2$ pg_ctl -D  /data/db01 stop
waiting for server to shut down....2021-10-12 08:51:20.555 CST [12010] LOG:  received fast shutdown request
2021-10-12 08:51:20.575 CST [12010] LOG:  aborting any active transactions
2021-10-12 08:51:20.581 CST [12010] LOG:  background worker "logical replication launcher" (PID 12027) exited with exit code 1
2021-10-12 08:51:20.581 CST [12022] LOG:  shutting down
2021-10-12 08:51:20.820 CST [12010] LOG:  database system is shut down
 done
server stopped

#设置开机自动启动脚本

postgresql-13.4/contrib/start-scripts/linux

#更该prefix:
prefix=/usr/local/postgresql

#更改PGDATA:
PGDATA="/data/db01"

cp linux /etc/init.d/postgres
chmod +x /etc/init.d/postgres

#测试开机状态

[root@VM-16-10-centos start-scripts]# /etc/init.d/postgres start
Starting PostgreSQL: ok
[root@VM-16-10-centos start-scripts]# /etc/init.d/postgres status
pg_ctl: server is running (PID: 15258)
/usr/local/postgresql/bin/postgres "-D" "/data/db01"
[root@VM-16-10-centos start-scripts]# /etc/init.d/postgres stop
Stopping PostgreSQL: ok

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。