Linux上生产环境源码方式安装配置postgresql12
1、Linux上源码方式安装postgresql12
01、准备操作系统环境
echo"192.168.1.61 tsepg61" >> /etc/hostsmount /dev/cdrom /mnt
02、安装pg所需要的依赖包
yuminstall -y cmake makegcc 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 pgsqluseradd
-u 60000 -g pgsql pgsqlecho"pgsql" |passwd --stdin pgsql
05、创建数据库相关目录
#安装目录:/postgresql/pg12
mkdir -p /postgresql/{pgdata,archive,scripts,backup,pg12,soft}chown -R pgsql:pgsql /postgresqlchmod -R 775 /postgresql
06、源码安装postgresql
#进入pgsql用户开始解压pg源码su - pgsqlcd
/postgresql/softtar zxvf postgresql-12.2.tar.gzcd postgresql
-12.2#prefix是安装的目录,
--without-readline代表命令行中不现实历史命令,就是history这个命令.
/configure --prefix=/postgresql/pg12 --without-readlinemakemakeinstall
07、配置数据库环境变量
su - pgsqlvi ~/.bash_profileexport LANG
=en_US.UTF8export PS1
="[`whoami`@`hostname`:""$PWD]$"export PGPORT
=5432export PGDATA
=/postgresql/pgdataexport PGHOME
=/postgresql/pg12export LD_LIBRARY_PATH
=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATHexport 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.confsu - 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 serverDocumentation
=man:postgres(1)[Service]
Type
=notifyUser
=pgsqlExecStart
= /postgresql/pg12/bin/postgres -D /postgresql/pgdataExecReload
=/bin/kill -HUP $MAINPIDKillMode
=mixedKillSignal
=SIGINTTimeoutSec
=0[Install]
WantedBy
=multi-user.target
#相关的开机启动命令
systemctl enable postgresqlsystemctl start postgresql
systemctl status postgresql
11、配置数据库超级用户密码
su - pgsql
psqlpassword 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
以上是 Linux上生产环境源码方式安装配置postgresql12 的全部内容, 来源链接: utcz.com/z/535771.html