暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

pg12 小白新手学安装(源码安装)

唯唯 2024-10-24
212

pg12 小白新手学安装(源码安装)

原文链接

1.下载地址

https://www.postgresql.org/download/

2.创建用户

useradd postgres
passwd postgres

3.安装依赖包

[root@dldbxkip4563 /tmp]#yum install make gcc zlib zlib-devel tar readline readline-devel perl perl-devel python python-devel openssl openssl-devel libxml2 libxml2-devel libxslt libxslt-devel perl-ExtUtils-Embed flex bison
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Repository epel is listed more than once in the configuration
Repository epel-debuginfo is listed more than once in the configuration
Repository epel-source is listed more than once in the configuration
base                                                                                                  | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                  | 5.1 kB  00:00:00
epel                                                                                                  | 4.3 kB  00:00:00
extras                                                                                                | 2.9 kB  00:00:00
updates                                                                                               | 2.9 kB  00:00:00
(1/5): extras/7/x86_64/primary_db                                                                     | 253 kB  00:00:00
(2/5): epel/x86_64/group                                                                              | 399 kB  00:00:01
(4/5)。。。。。一下省略几千字。。。

4.创建目录并授权

mkdir -p /data/pgsqldata/5432/data
mkdir -p /data/pgsqldata/5432/logs
chown -R postgres /data/pgsqldata/5432
chmod 700 -R /data/pgsqldata/5432/data

5.修改系统参数

vi /etc/sysctl.conf
kernel.shmmax=68719476736
kerne1.shma11=4294967296
kernel.shmmni =4096
kerne1.sem=50100 64128000 50100 1280
fs.file-max=7672460
net.ipv4.ip_1oca1_port_range =9000 65000
net.core.rmem_default=1048576
net.core.rmem_max=4194304
net.core.wmem_defau1t=262144
net.core.wmem_max=1048576

sysctl -p

vi /etc/security/limits.conf
* soft nproc 131072
* hard nproc 131072
* soft nofile 131072
* hard nofile 131072
* soft core unlimited
* hard core unlimited
* soft memlock 50000000
* hard memlock 50000000

6.关闭防火墙

systemctl disable firewalld
systemctl stop firewalld

7.解压安装

tar zxvf /opt/postgresql-12.1.tar.gz -C /opt/

cd /opt/postgresql-12.1
[root@dldbxkip4563 /opt/postgresql-12.10]#./configure --prefix=/usr/local/pgsql121 --with-pgport=5432 --enable-nls--with-perl --with-python --with-libxml --with-libxsltchecking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking which template to use... linux
checking whether NLS is wanted... yes
checking for default port number... 5432
checking for block size... 8kB
checking for segment size... 1GB
checking for WAL block size... 8kB
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
..........
checking for dbtoepub... no
checking thread safety of required library functions... yes
checking whether gcc -std=gnu99 supports -Wl,--as-needed... yes
configure: using compiler=gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
configure: using CFLAGS=-Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -O2
configure: using CPPFLAGS= -D_GNU_SOURCE -I/usr/include/libxml2
configure: using LDFLAGS=  -Wl,--as-needed
configure: creating ./config.status
config.status: creating GNUmakefile
config.status: creating src/Makefile.global
config.status: creating src/include/pg_config.h
config.status: creating src/include/pg_config_ext.h
config.status: creating src/interfaces/ecpg/include/ecpg_config.h
config.status: linking src/backend/port/tas/dummy.s to src/backend/port/tas.s
config.status: linking src/backend/port/posix_sema.c to src/backend/port/pg_sema.c
config.status: linking src/backend/port/sysv_shmem.c to src/backend/port/pg_shmem.c
config.status: linking src/include/port/linux.h to src/include/pg_config_os.h
config.status: linking src/makefiles/Makefile.linux to src/Makefile.port
make world #make world = make clean + make dist
make install

软连接:
ln -s /usr/local/pgsql121 /usr/local/pgsql
chown -R postgres.postgres /usr/local/pgsql121
chown -R postgres.postgres /usr/local/pgsql

8.配置环境变量

[postgres@dldbxkip4563 ~]$cat .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH
export PGDATA=/data/pgsqldata/5432/data
export PGHOME=/usr/local/pgsql
export LANG=en_uS.utf8
export LD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATH
export DATE=`date +"%Y%m%d%H%M"`
export PATH=$PGHOME/bin:$PATH
export MANPATH=$PGHOME/share/man:$MANPATH
export PGUSER=postgres

source .bash_profile

9.初始化数据

su - postgres
[postgres@dldbxkip4563 ~]$initdb -D /data/pgsqldata/5432/data -U postgres  -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 "en_US.UTF8".
The default database encoding has accordingly been set to "UTF8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

Enter new superuser password:
Enter it again:

fixing permissions on existing directory /data/pgsqldata/5432/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... PRC
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:

    pg_ctl -D /data/pgsqldata/5432/data -l logfile start

[postgres@dldbxkip4563 ~]$pg_ctl -D /data/pgsqldata/5432/data -l logfile start
waiting for server to start.... done
server started
[postgres@dldbxkip4563 ~]$

postgres 密码pg123456

10.登录

[postgres@dldbxkip4563 ~]$psql -U postgres
psql (12.10)
Type "help" for help.

postgres=#

11 .附加

总结遇到的相关问题如下:

【问题1】:

checking for dtrace... no
configure: error: dtrace not found
解决方法:
yum search dtrace
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
=============================================================================================== Matched: dtrace ===============================================================================================
systemtap-sdt-devel.i686 : Static probe support tools
systemtap-sdt-devel.x86_64 : Static probe support tools

找到了,就安装,我是64位的,安装第二个
yum install -y systemtap-sdt-devel.x86_64

【问题2】:
checking for flags to link embedded Perl... Can't locate ExtUtils/Embed.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
no
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is not
installed.
解决方法:
yum install perl-ExtUtils-Embed -y

【问题3】:
configure: error: could not determine flags for linking embedded Perl.
This probably means that ExtUtils::Embed or ExtUtils::MakeMaker is not
installed.
解决方法:
yum install perl-ExtUtils-Embed

【问题4】:
configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

解决方法:
yum install readline readline-devel

【问题5】:
checking for inflate in -lz... no
configure: error: zlib library not found
If you have zlib already installed, see config.log for details on the
failure. It is possible the compiler isn't looking in the proper directory.
Use --without-zlib to disable zlib support.
解决方法:
yum install zlib zlib-devel

【问题6】:
checking for CRYPTO_new_ex_data in -lcrypto... no
configure: error: library 'crypto' is required for OpenSSL
解决方法:
yum install openssl openssl-devel

【问题7】:
checking for pam_start in -lpam... no
configure: error: library 'pam' is required for PAM
解决方法:
yum install pam pam-devel

【问题8】:
checking for xmlSaveToBuffer in -lxml2... no
configure: error: library 'xml2' (version >= 2.6.23) is required for XML support
解决方法:
yum install libxml2 libxml2-devel

【问题9】:
checking for xsltCleanupGlobals in -lxslt... no
configure: error: library 'xslt' is required for XSLT support
解决方法:
yum install libxslt libxslt-devel

【问题10】:
configure: error: Tcl shell not found
解决方法:
yum install tcl tcl-devel

【问题11】:
checking for ldap.h... no
configure: error: header file is required for LDAP
解决方法:
yum install openldap openldap-devel

【问题12】:
checking for Python.h... no
configure: error: header file <Python.h> is required for Python
解决方法:
yum install python python-devel (注意有的机器上需要指定python版本,例如python2-devel或python3.6-devel)

【问题13】:
Error when bootstrapping CMake:
Cannot find appropriate C++ compiler on this system.
Please specify one using environment variable CXX.
See cmake_bootstrap.log for compilers attempted.
解决方法:
yum install gcc-c++

【问题14】:

configure: error: Package requirements (liblz4) were not met:

No package 'liblz4' found
原因是缺少liblz4依赖包。
解决办法:
安装liblz4相关包
sudo yum install epel-release
yum install lz4
sudo yum install lz4-devel

最后修改时间:2024-10-24 16:29:56
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论