原 在openEuler 22.03上分别使用yum和编译安装PostgreSQL环境
Tags: 原创PGPostgreSQL安装部署openEuleryumdnf安装22.03
环境申请
由于环境要国产化,选择openEuler 22.03 LTS
系统,这里测试一下在openEuler上安装PG,过程如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | docker rm -f lhropeneuler22 docker run -itd --name lhropeneuler22 -h lhropeneuler22 \ -p 15432:5432 -p 7389:3389 \ --privileged=true \ -v /sys/fs/cgroup:/sys/fs/cgroup \ lhrbest/openeuler22:6.0 \ init docker exec -it lhropeneuler22 bash [root@lhropeneuler22 /]# cat /etc/os-release NAME="openEuler" VERSION="22.03 LTS" ID="openEuler" VERSION_ID="22.03" PRETTY_NAME="openEuler 22.03 LTS" ANSI_COLOR="0;31" |
安装PG
yum在线安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | -- 默认安装PG 13.12 dnf install -y postgresql postgresql-server postgresql-contrib postgresql-server-devel postgresql-llvmjit [root@lhropeneuler22 soft]# rpm -aq| grep postgres postgresql-13.12-1.oe2203.x86_64 postgresql-contrib-13.12-1.oe2203.x86_64 postgresql-server-13.12-1.oe2203.x86_64 postgresql-llvmjit-13.12-1.oe2203.x86_64 postgresql-server-devel-13.12-1.oe2203.x86_64 -- 初始化 /usr/bin/postgresql-setup initdb systemctl enable postgresql.service systemctl start postgresql.service systemctl status postgresql.service [root@lhropeneuler22 /]# systemctl status postgresql.service ● postgresql.service - PostgreSQL database server Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2023-03-10 12:28:14 CST; 9s ago Process: 4453 ExecStartPre=/usr/libexec/postgresql-check-db-dir postgresql (code=exited, status=0/SUCCESS) Main PID: 4455 (postmaster) Tasks: 8 (limit: 411139) Memory: 14.0M CGroup: /docker/54a7256274ea4b7de2c11b57c7f07226a520c34178effcb3a06b2da35ea96144/system.slice/postgresql.service ├─4455 /usr/bin/postmaster -D /var/lib/pgsql/data ├─4456 "postgres: logger " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─4458 "postgres: checkpointer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─4459 "postgres: background writer " "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─4460 "postgres: walwriter " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─4461 "postgres: autovacuum launcher " "" "" "" "" "" "" "" "" "" "" "" "" ├─4462 "postgres: stats collector " "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" └─4463 "postgres: logical replication launcher " "" "" "" Mar 10 12:28:14 lhropeneuler22 systemd[1]: Starting PostgreSQL database server... Mar 10 12:28:14 lhropeneuler22 postmaster[4455]: 2023-03-10 12:28:14.227 CST [4455] LOG: redirecting log output to logging collector process Mar 10 12:28:14 lhropeneuler22 postmaster[4455]: 2023-03-10 12:28:14.227 CST [4455] HINT: Future log output will appear in directory "log". Mar 10 12:28:14 lhropeneuler22 systemd[1]: Started PostgreSQL database server. -- 重新初始化中文 --locale=en_US.utf8 su - postgres rm -rf /var/lib/pgsql/data/ /usr/bin/initdb -D /var/lib/pgsql/data -E UTF8 --locale=zh_CN.UTF-8 -U postgres --data-checksums |
离线安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | rpm -ivh sudo*.rpm lrzsz*.rpm rpm -ivh net-tools-*.rpm --nodeps rpm -ivh libicu*.rpm --nodeps rpm -ivh systemd*.rpm --nodeps rpm -ivh systemd-249*.rpm --nodeps rpm -ivh perl*.rpm --nodeps rpm -ivh python3*.rpm --nodeps rpm -ivh libxslt*.rpm rpm -ivh openssl*.rpm --nodeps rpm -ivh llvm*.rpm scl-utils*.rpm libedit-devel*.rpm --nodeps rpm -ivh cpp*.rpm libmpc*.rpm glibc-devel*.rpm automake*.rpm autoconf*.rpm libtool*.rpm --nodeps rpm -ivh cmake*.rpm make*.rpm gcc*.rpm --nodeps rpm -ivh ncurses-devel*.rpm --nodeps rpm -ivh libarchive*.rpm --nodeps rpm -ivh compat-openssl10*.rpm findutils*.rpm --nodeps rpm -ivh kmod-libs*.rpm --nodeps rpm -ivh libseccomp*.rpm --nodeps rpm -ivh util-linux*.rpm --nodeps rpm -ivh libpq*.rpm uuid*.rpm krb5-devel*.rpm --nodeps rpm -ivh libstdc*.rpm --force rpm -ivh binutils*.rpm clang*.rpm kernel-headers*.rpm emacs-filesystem*.rpm --nodeps rpm -ivh readline*.rpm readline-devel*.rpm --force --nodeps rpm -ivh isl*.rpm libgcc*.rpm libgomp*.rpm gmp*.rpm --nodeps --force rpm -ivh guile*.rpm zlib*.rpm gc-*.rpm isl*.rpm --nodeps --force rpm -ivh readline*.rpm readline-devel*.rpm --force --nodeps -- rpm -ivh libzstd*.rpm -- rpm -ivh systemd-sysv-*.rpm --nodeps -- rpm -ivh devtoolset*.rpm mpfr*.rpm tcl*.rpm -- yum localinstall -y *.rpm --skip-broken ln -s /usr/lib64/libldap.so.2.0.200 /usr/lib64/libldap-2.4.so.2 ln -s /usr/lib64/libldap.so.2.0.200 /usr/lib64/libldap_r-2.4.so.2 ln -s /usr/lib64/libreadline.so.8.1 /usr/lib64/libreadline.so.6 ln -s /usr/lib64/libreadline.so.8.1 /usr/lib64/libreadline.so.7 ln -s /usr/lib64/libicui18n.so.69.1 /usr/lib64/libicui18n.so.50 ln -s /usr/lib64/libicui18n.so.69.1 /usr/lib64/libicui18n.so.60 ln -s /usr/lib64/libicuuc.so.69.1 /usr/lib64/libicuuc.so.50 ln -s /usr/lib64/libicuuc.so.69.1 /usr/lib64/libicuuc.so.60 ln -s /usr/lib64/libpython3.9.so.1.0 /usr/lib64/libpython3.6m.so.1.0 ln -s /usr/lib64/libperl.so.5.34.0 /usr/lib64/libperl.so.5.26 rpm -ivh postgresql-13*.rpm rpm -ivh postgresql-contrib-13*.rpm rpm -ivh postgresql-server-13*.rpm rpm -ivh postgresql-llvmjit-13*.rpm rpm -ivh postgresql-server-devel-13*.rpm /* -- 报错 rpm -ivh postgresql15-libs-15.4-1PGDG.rhel7.x86_64.rpm --nodeps rpm -ivh postgresql15-15.4-1PGDG.rhel7.x86_64.rpm --nodeps rpm -ivh postgresql15-server-15.4-1PGDG.rhel7.x86_64.rpm --nodeps rpm -ivh postgresql15-contrib-15.4-1PGDG.rhel7.x86_64.rpm --nodeps rpm -ivh postgresql15-devel-15.4-1PGDG.rhel7.x86_64.rpm --nodeps dnf install -y libxslt --downloadonly --downloaddir=/soft/tmp/ */ |
环境变量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | mkdir -p /home/postgres chown postgres.postgres /home/postgres -R sed -i 's|/var/lib/pgsql|/home/postgres|' /etc/passwd echo "lhr" |passwd --stdin postgres echo "postgres ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers cat > /home/postgres/.bash_profile <<"EOF" export PGPORT=5432 # export PGHOME=/usr/pgsql-15 export PGDATA=/var/lib/pgsql/data export PATH=$PGHOME/bin:$PATH export MANPATH=$PGHOME/share/man:$MANPATH export LANG=en_US.UTF-8 export DATE='date +"%Y%m%d%H%M"' export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATH export PGHOST=$PGDATA export PGUSER=postgres export PGPASSWORD=lhr export PGDATABASE=postgres export PS1="[\u@\h \W]\$ " EOF chown postgres.postgres /home/postgres/.bash_profile systemctl restart postgresql.service systemctl status postgresql.service |
修改密码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | -- 本地登陆 su - postgres psql -- 安装插件 create extension pageinspect; create extension pg_stat_statements; select * from pg_extension ; select * from pg_available_extensions order by name; postgres=# select * from pg_extension ; oid | extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition -------+--------------------+----------+--------------+----------------+------------+-----------+-------------- 13490 | plpgsql | 10 | 11 | f | 1.0 | | 16384 | pageinspect | 10 | 2200 | t | 1.8 | | 16416 | pg_stat_statements | 10 | 2200 | t | 1.8 | | (3 rows) postgres=# -- 修改postgres密码 alter user postgres with encrypted password 'lhr'; 或 \password select * from pg_tables; select version(); postgres=# select version(); version ------------------------------------------------------------------------------------------ PostgreSQL 13.12 on x86_64-openEuler-linux-gnu, compiled by gcc_old (GCC) 10.3.1, 64-bit (1 row) |