暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片
pg12.3部署之linux.txt
343
8页
23次
2022-08-29
免费下载
https://blog.csdn.net/weixin_39540651/article/details/100582554
https://www.postgresql.org/ftp/source/
https://ftp.postgresql.org/pub/source/v12.1/postgresql-12.1.tar.gz
1 准备环境
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-
devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
bison flex 1
2 创建数据目录并授权
openssl rand -base64 8
groupadd postgres
useradd -g postgres -G postgres -d /home/postgres postgres
mkdir -p /data/pg123/{data,arch_wal,backup}
mkdir -p /usr/local/pg123/
chown -R postgres:postgres /data/pg123
chown -R postgres:postgres /usr/local/pg123
配置环境变量
echo "export PGPORT=5432
export PGUSER=postgres
export PGHOME=/usr/local/pg123
export PGDATA=/data/pg123/data
export PATH=$PGHOME/bin:$PATH
export LANG=en_US.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH"
>> /home/postgres/.bash_profile
source /home/postgres/.bash_profile
vim /home/postgres/.bashrc
PS1="[\u@\h: \w]\\$ "
alias dstat='dstat -cdlmnpsy'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias vi='vim'
alias ls='ls --color=always'
alias ll='ls -trhl --color=always --time-style=long-iso'
alias grep='grep --color=always'
alias egrep='egrep --color=always'
source /home/postgres/.bashrc
3 编译安装
编译
tar zxf postgresql-12.3.tar.gz -C /usr/local/
cd /usr/local/postgresql-12.3/
./configure --prefix=/usr/local/pg123 --with-python --with-openssl
./configure --prefix=/usr/local/pgsql --with-pgport=${port} --with-perl --with-
python --with-openssl --with-pam --with-ldap --with-libxml --with-libxslt
--enable-thread-safety --with-wal-blocksize=16 --with-blocksize=16
gmake world && gmake install-world
cd contrib && make && make install
ln /usr/local/pg123 /usr/local/pgsql
echo "/usr/local/pgsql/lib/" >> /etc/ld.so.conf
#gmake world 表示编译所有能编译的东西,包括文档和附加模块, gmake 不会安装这些内容。扩展模块放
/share/extesion 目录下
#11G 开始使用 initdb 命令初始化时可以使用–wal-segsize 选项配置 WAL 段文件的大小。
pg_resetwal --wal-segsize=1024 /data/pg123/data
#默认 wal 16MB 的文件,内部切分为 8192 字节(8K)的页面
#指定 8kb 的数据块,16kb WAL 日志块,1024MB WAL 日志文件
--with-blocksize=8 --with-wal-blocksize=16 --with-wal-segsize=1024
内置函数 pg_xlogfile_name10 之前)或 pg_walfile_name10 开始),可以找到包含指定 LSN
WAL 文件名:
select pg_xlogfile_name('1/00002D3E'); (10 开始或之后)select
pg_walfile_name('1/00002D3E');
更多 WAL 介绍:https://blog.csdn.net/Hehuyi_In/article/details/103029844
--如果需要使用 uuid 需要编译时指定参数,具体百度
with-wal-segsize 更改 WAL 日志大小,默认 16M
####
4 配置数据库
su - postgres
initdb -D /data/pg123/data -U postgres --locale=en_US.UTF8 -E UTF8 -W
cp /data/pg123/data/{pg_hba.conf,pg_hba.conf.bak}
cp /data/pg123/data/{postgresql.conf,postgresql.conf.bak}
pg_ctl -D /data/pg123/data -l logfile start
修改密码
#alter user postgres with password '123';
revoke create on schema public from public;
CREATE ROLE repl WITH PASSWORD '123' REPLICATION LOGIN;
CREATE role test WITH LOGIN NOSUPERUSER CREATEDB NOCREATEROLE INHERIT CONNECTION
LIMIT -1 password '123';
create schema test authorization test;
或不指定 schema 名称使用 user 名称
create schema authorization test;
2.创建一个表空间
mkdir /data/pg123/tabspc/test -p (确保属于 postgres 用户属组,且目录为空)
CREATE TABLESPACE tabspc_test OWNER test LOCATION '/data/pg123/tabspc/test';
3.创建一个数据库,指明该数据库的表空间是刚刚创建的 tabspc_test
CREATE DATABASE test TEMPLATE template1 OWNER test TABLESPACE tabspc_test;
#创建临时表空间
mkdir /data/pg123/tabspc/temp01 -p
create tablespace temp01 location '/data/pg123/tabspc/temp01';
alter role all set temp_tablespaces='temp01';
set temp_tablespaces = 'temp01';
--scott 表空间创建
CREATE role scott WITH LOGIN NOSUPERUSER CREATEDB NOCREATEROLE INHERIT
CONNECTION LIMIT -1 password '123';
create schema scott authorization scott;
或不指定 schema 名称使用 user 名称 se
#create schema authorization scott;
2.创建一个表空间
mkdir /data/pg123/tabspc/scott -p (确保属于 postgres 用户属组,且目录为空)
CREATE TABLESPACE tabspc_scott OWNER scott LOCATION '/data/pg123/tabspc/scott';
3.创建一个数据库,指明该数据库的表空间是刚刚创建的 tabspc_yy
CREATE DATABASE scott TEMPLATE template1 OWNER scott TABLESPACE tabspc_scott;
insert into userinfo select
generate_series(2,10000000),'test',clock_timestamp();
INSERT 0 9999999
## 允许 repl 用户进行流复制
cat <<-eof >>/data/pg123/data/pg_hba.conf
host all all 0.0.0.0/0 md5
host replication repl 192.98.8.0/32 md5
of 8
免费下载
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文档的来源(墨天轮),文档链接,文档作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论

关注
最新上传
暂无内容,敬请期待...
下载排行榜
Top250 周榜 月榜