Postgresql 소스 코드 컴파일 및 설치(linux-postgresql13.8)

Postgresql 소스 코드 컴파일 및 설치(linux-postgresql13.8)

1. 설치 패키지 다운로드

postgresql官方下载地址:https://www.postgresql.org/ftp/source/

2. 환경적 준비

1. 최대 사용자 프로세스 수 수정

cat >> /etc/security/limits.conf << 'EOF'
* soft     nproc          65535
* hard     nproc          65535
* soft     nofile         65535
* hard     nofile         65535
EOF

2. 일반 사용자 수정

cat >> /etc/security/limits.d/90-nproc.conf << 'EOF'

*          soft     nproc          65535
*          hard     nproc          65535
*          soft     nofile         65535
*          hard     nofile         65535
EOF

3. 파일 핸들 수 수정

cat >> /etc/sysctl.conf << 'EOF'
fs.file-max = 65536
EOF

4. 검증

 ulimit -a

5. 설치 종속성

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 perl python36 tcl openssl-devel ncurses-devel openldap pam

3. 설치 단계

압축을 풀다

tar -zxvf postgresql-13.8.tar.gz

설치 디렉토리를 입력하십시오

cd postgresql-13.8

컴파일된 파일 생성

/home/pgsql/은 필요에 따라 수정할 수 있는 설치 경로입니다.

./configure \
--prefix=/home/pgsql \
--bindir=/home/pgsql/bin \
--with-pgport=5432 \
--with-wal-blocksize=16 \
--with-segsize=1 \
--with-blocksize=8 \
--with-libedit-preferred \
--with-perl \
--with-openssl \
--with-libxml \
--with-libxslt \
--enable-thread-safety

엮다

make -j4 

설치하다

make -j4 install

postgresql 사용자 생성,

useradd postgres

데이터 저장소 디렉터리 생성 및 권한 부여

mkdir /home/pgsql/data
chown postgres.postgres -R /home/pgsql

사용자 전환

su - postgres

환경 변수 설정

cat >>.bash_profile EOF
export PGDATA=/home/pgsql/data
export PGHOME=/home/pgsql/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib
export PATH=$PATH:$PGHOME/bin/
EOF

환경 변수가 적용됨

source .bash_profile

데이터베이스 초기화

su - postgres

initdb

postgresql.conf 파일 구성 매개변수

cat >> /home/pgsql/data/postgresql.conf <<'EOF'
listen_addresses = '*'
port=5432
unix_socket_directories='/home/pgsql/data'
wal_level = logical
logging_collector = on
log_directory = 'pg_log'
log_filename = 'postgresql-%a.log'
log_truncate_on_rotation = on
log_timezone = 'Asia/Shanghai'
timezone = 'Asia/Shanghai'
max_wal_size = 1GB
min_wal_size = 80MB
dynamic_shared_memory_type = posix      # the default is the first option
shared_buffers = 128MB                  # min 128kB
max_connections = 1000                   # (change requires restart)
datestyle = 'iso, ymd'
lc_messages = 'zh_CN.UTF-8'                     # locale for system error message  # strings
lc_monetary = 'zh_CN.UTF-8'                     # locale for monetary formatting
lc_numeric = 'zh_CN.UTF-8'                      # locale for number formatting
lc_time = 'zh_CN.UTF-8'                         # locale for time formatting
default_text_search_config = 'pg_catalog.simple'
EOF

pg_hba.conf 파일 원격 로그인 구성 매개변수

cat   > /home/pgsql/data/pg_hba.conf << EOF
# TYPE  DATABASE    USER    ADDRESS       METHOD
local     all       all                    trust
local   replication     all                                     trust
host      all       all   127.0.0.1/32     trust
host      all       all    0.0.0.0/0        md5
host    replication     all    127.0.0.1/32    trust
host   replication  all    0.0.0.0/0        md5
EOF

시스템 서비스 구성(루트 사용자 사용)

cat > /etc/systemd/system/postgresql-13.service <<'EOF'
[Unit]
Description=PostgreSQL database server
Documentation=man:postgres(1)
After=network.target
[Service]
Type=forking
User=postgres
Group=postgres
Environment=PGPORT=5432
Environment=PGDATA=/home/pgsql/data
OOMScoreAdjust=-1000
ExecStart=/home/pgsql/bin/pg_ctl start -D ${
    
    PGDATA} -s -o '-p ${
    
    PGPORT}' -w -t 300
ExecStop=/home/pgsql/bin/pg_ctl stop -D ${
    
    PGDATA} -s -m fast
ExecReload=/home/pgsql/bin/pg_ctl reload -D ${
    
    PGDATA} -s
KillMode=mixed
KillSignal=SIGINT
TimeoutSec=0
[Install]
WantedBy=multi-user.target
EOF

시스템 환경 변수 구성

export PATH=$PATH:/home/pgsql/bin/

환경 변수가 적용됨

source /etc/profile

부팅 자체 시작

systemctl status postgresql-13
systemctl enable postgresql-13

버전 정보 보기

psql --version

데이터베이스 테스트에 로그인합니다. 기본 포트는 5432입니다.

psql -h 127.0.0.1 -U postgres

비밀번호 변경

\password
或
alter user postgres with password '密码'

설치 완료!

추천

출처blog.csdn.net/LSW1737554365/article/details/129789740