linux 安装PG12

VM虚拟机

操作系统:中标麒麟V10 64位 AMD64

内存因条件限制只分配了1G

软件: postgresql-12.1.tar.gz

[root@test04 ~]# uname -a
Linux test04 4.19.90-24.4.v2101.ky10.x86_64 #1 SMP Mon May 24 12:14:55 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
[root@test04 ~]# uname -r
4.19.90-24.4.v2101.ky10.x86_64

检查系统是否已安装pg

[root@test04 postgresql-12.1]# yum list installed|grep postgres
postgresql-libs.x86_64                      10.5-19.p01.ky10                @anaconda 
qt5-qtbase-postgresql.x86_64                5.11.1-11.p01.ky10              @anaconda 
[root@test04 postgresql-12.1]# yum remove postgresql*

关闭selinux,重启生效

修改内容:SELINUX=disabled

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     ukmls - Multi Level Security protection.
#     ukmcs -ukmcs variants of the SELinux policy.
SELINUXTYPE=ukmcs

# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0

虚拟机本地yum源配置:

mkdir -p /mnt/cdrom

[kylin-yum]
name=kylin
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=0

yum clean all
yum makecache

[root@test04 yum.repos.d]# yum -y install readline readline-devel zlib zlib-devel gettext gettext-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl perl-devel tcl-devel uuid-devel gcc gcc-c++ make flex bison perl-ExtUtils*

vi /etc/sysctl.conf  根据需求设置

查看时间同步:

[root@test04 ~]# timedatectl status
               Local time: 日 2021-09-19 20:27:36 CST
           Universal time: 日 2021-09-19 12:27:36 UTC
                 RTC time: 日 2021-09-19 12:27:36
                Time zone: Asia/Shanghai (CST, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

创建用户&组

[root@test04 ~]# groupadd pgdba -g 2000
[root@test04 ~]# useradd postgres -g 2000 -u 2000
[root@test04 ~]# id postgres
用户id=2000(postgres) 组id=2000(pgdba) 组=2000(pgdba)
[root@test04 ~]# passwd postgres

创建目录:源文件/安装文件/数据/wal/归档目录

[root@test04 /]# mkdir -p /opt/pg12
[root@test04 /]# mkdir -p /opt/pgdata
[root@test04 /]# mkdir -p /opt/pgwal
[root@test04 /]# mkdir -p /opt/pgarchive

修改权限

chown -R postgres:pgdba /soft /opt

vi  /etc/security/limits.conf 调整资源限制参数

上传安装包,解压安装包

[root@test04 ~]# su - postgres
[postgres@test04 ~]$ cd /soft/
[postgres@test04 soft]$ ll
总用量 25812
-rw-r--r-- 1 root root 26428138  9月 19 20:49 postgresql-12.1.tar.gz
[postgres@test04 soft]$ tar -zxvf postgresql-12.1.tar.gz 

解压后进入文件夹

[postgres@test04 soft]$ cd postgresql-12.1/
[postgres@test04 postgresql-12.1]$ ll
总用量 740
-rw-r--r--  1 postgres pgdba    522 11月 12  2019 aclocal.m4
drwxr-xr-x  2 postgres pgdba   4096 11月 12  2019 config
-rwxr-xr-x  1 postgres pgdba 571134 11月 12  2019 configure
-rw-r--r--  1 postgres pgdba  82903 11月 12  2019 configure.in
drwxr-xr-x 56 postgres pgdba   4096 11月 12  2019 contrib
-rw-r--r--  1 postgres pgdba   1192 11月 12  2019 COPYRIGHT
drwxr-xr-x  3 postgres pgdba     87 11月 12  2019 doc
-rw-r--r--  1 postgres pgdba   3909 11月 12  2019 GNUmakefile.in
-rw-r--r--  1 postgres pgdba    284 11月 12  2019 HISTORY
-rw-r--r--  1 postgres pgdba  61608 11月 12  2019 INSTALL
-rw-r--r--  1 postgres pgdba   1665 11月 12  2019 Makefile
-rw-r--r--  1 postgres pgdba   1212 11月 12  2019 README
drwxr-xr-x 16 postgres pgdba    328 11月 12  2019 src

编译安装:

[postgres@test04 postgresql-12.1]$ ./configure --prefix=/opt/pg12 --with-pgport=5432

执行gmake 或gmake world编译

[postgres@test04 postgresql-12.1]$ gmake world

[postgres@test04 postgresql-12.1]$ gmake install-world

初始化数据目录

[postgres@test04 opt]$ /opt/pg12/bin/initdb -D /opt/pgdata -X /opt/pgwal -EUTF8 -Upostgres -W

 

[postgres@test04 opt]$ /opt/pg12/bin/initdb -D /opt/pgdata -X /opt/pgwal -EUTF8 -Upostgres -W
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 "zh_CN.UTF-8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

Enter new superuser password: 
Enter it again: 

fixing permissions on existing directory /opt/pgdata ... ok
fixing permissions on existing directory /opt/pgwal ... 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:

    /opt/pg12/bin/pg_ctl -D /opt/pgdata -l logfile start

开启数据库:

[postgres@test04 opt]$ /opt/pg12/bin/pg_ctl -D /opt/pgdata -l logfile start
waiting for server to start.... done
server started

查看数据库状态:

[postgres@test04 opt]$ /opt/pg12/bin/pg_ctl -D /opt/pgdata status
pg_ctl: server is running (PID: 15955)
/opt/pg12/bin/postgres "-D" "/opt/pgdata"

关闭数据库使用/opt/pg12/bin/pg_ctl -D /opt/pgdata stop

重启数据库使用/opt/pg12/bin/pg_ctl -D /opt/pgdata restart

 /opt/pgdata/postgresql.conf可修改数据库配置参数

 配置环境变量:

[postgres@test04 opt]$ cat ~/.bash_profile 
# Source /root/.bashrc if user has one
[ -f ~/.bashrc ] && . ~/.bashrc
export PGPORT=5432
export PGUSER=postgres
export PGHOME=/opt/pg12
export PGDATA=/opt/pgdata
export PATH=$PGHOME/bin:$PATH

环境变量生效:

source ~/.bash_profile 

psql工具连接数据库:

 

开启日志:

 重启数据库:

新日志生成:

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DHY151

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值