Linux上生产环境源码方式安装配置postgresql12

1、Linux上源码方式安装postgresql12

01、准备操作系统环境

echo "192.168.1.61 tsepg61" >> /etc/hosts
mount /dev/cdrom /mnt
 

02、安装pg所需要的依赖包

yum install -y cmake make gcc zlib gcc-c++ perl readline readline-devel zlib \
zlib-devel perl python36 tcl openssl ncurses-devel openldap pam

 

03、下载pg程序并上传到服务器

#PG这边用的安装包提供了yum和source源码方式 #所以生产环境为了方便管理就用源码source包安装合适些 https://www.postgresql.org/ftp/source/  

04、创建pg普通用户

groupadd -g 60000 pgsql
useradd -u 60000 -g pgsql pgsql
echo "pgsql" |passwd --stdin pgsql

 

05、创建数据库相关目录

#安装目录:/postgresql/pg12
mkdir -p /postgresql/{pgdata,archive,scripts,backup,pg12,soft}
chown -R pgsql:pgsql /postgresql
chmod -R 775 /postgresql

 

06、源码安装postgresql

#进入pgsql用户开始解压pg源码
su - pgsql
cd /postgresql/soft
tar zxvf postgresql-12.2.tar.gz
cd postgresql-12.2
#prefix是安装的目录,--without-readline代表命令行中不现实历史命令,就是history这个命令
./configure --prefix=/postgresql/pg12 --without-readline
make
make install
 

07、配置数据库环境变量

su - pgsql
vi ~/.bash_profile
export LANG=en_US.UTF8
export PS1="[`whoami`@`hostname`:"'$PWD]$'
export PGPORT=5432
export PGDATA=/postgresql/pgdata
export PGHOME=/postgresql/pg12
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export PATH=$PGHOME/bin:$PATH:.
export MANPATH=$PGHOME/share/man:$MANPATH

 

08、初始化数据库

su - pgsql
/postgresql/pg12/bin/initdb -U postgres -D /postgresql/pgdata -E UTF8 --locale=en_US.utf8

 

09、配置参数文件

/postgresql/pgdata/postgresql.conf
/postgresql/pgdata/pg_hba.conf
su - pgsql
#pg服务启动 pg_ctl start pg_ctl stop
#or或者命令启动
nohup /postgresql/pg12/bin/postgres -D /postgresql/pgdata > /postgresql/pg12/pglog.out 2>&1 &

#or或者写成服务配置开机启动

vi /etc/systemd/system/postgresql.service
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
[Service]
Type=notify
User=pgsql
ExecStart= /postgresql/pg12/bin/postgres -D /postgresql/pgdata
ExecReload=/bin/kill -HUP $MAINPID
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
[Install]
WantedBy=multi-user.target
#相关的开机启动命令
systemctl enable postgresql
systemctl start postgresql
systemctl status postgresql

 

11、配置数据库超级用户密码

su - pgsql
psql \password postgres #or: alter user postgres with password '123456';

 

12、创建表测试

create table tsetbs (name varchar(50));
insert into tsetbs values('百度');
insert into tsetbs values('阿里');
insert into tsetbs values('腾讯');
insert into tsetbs values('www.baidu.com');
insert into tsetbs values('wx');
insert into tsetbs values('yone-com');
insert into tsetbs values('wx-gzh');
insert into tsetbs values('yone_com');
insert into tsetbs values('oracle');
insert into tsetbs values('mysql');
insert into tsetbs values('nosql');
insert into tsetbs values('pgsql');
insert into tsetbs values('深圳');
insert into tsetbs values('广州');
select * from tsetbs;

 

13、登陆及测试使用

psql -U postgres -h127.0.0.1
\

 

上一篇:WinSock TCP C/S通信示例


下一篇:029.PGSQL-pgsql创建新用户登录报错psql: FATAL: role "pguser" is not permitted to log in