AIOps 一场颠覆传统运维的盛筵
740
2022-09-29
Postgresql日常运维-安装(Linux)01
一:Linux下安装Postgresql
二:Windows下安装Postgresql
一:Linux下安装Postgresql
环境说明:
Linux OS:Red Hat Enterprise Linux Server release 7.5 (Maipo)
Windows OS:Windows 10
DB:PostgreSQL 12.2
1 下载PostgreSQL 12.2
https://postgresql.org/
二进制包下载
源码包下载
本次实验使用源码包
......
[root@cjcos package]# pwd
/package
[root@cjcos package]# ll -rth postgresql-12.2.tar.gz
-rw-r--r-- 1 root root 26M Apr 2 11:11 postgresql-12.2.tar.gz
[root@cjcos package]# md5sum postgresql-12.2.tar.gz
939acc9359abf0de9838965947a19158 postgresql-12.2.tar.gz
2 创建用户,组,目录等
[root@cjcos ~]# groupadd postgres
[root@cjcos ~]# useradd -g postgres postgres
[root@cjcos ~]# passwd postgres
[root@cjcos ~]# mkdir /usr/local/pgsql/data -p
[root@cjcos ~]# chown postgres.postgres /usr/local/pgsql -R
[root@cjcos package]# chown postgres.postgres /package/postgres -R
3 解压
[root@cjcos package]# su - postgres
[postgres@cjcos ~]$ cd /package/postgres/
[postgres@cjcos postgres]$ ll -rth
total 26M
-rw-r--r-- 1 postgres postgres 26M Apr 2 11:11 postgresql-12.2.tar.gz
[postgres@cjcos postgres]$ tar -zxvf postgresql-12.2.tar.gz
4 安装
[postgres@cjcos postgres]$ cd postgresql-12.2/
[postgres@cjcos postgresql-12.2]$ pwd
/package/postgres/postgresql-12.2
[postgres@cjcos postgresql-12.2]$ ./configure --prefix=/usr/local/pgsql
[postgres@cjcos postgresql-12.2]$ make
......
All of PostgreSQL successfully made. Ready to install.
[postgres@cjcos postgresql-12.2]$ make install
......
PostgreSQL installation complete.
[root@cjcos pgsql]# pwd
/usr/local/pgsql
[root@cjcos pgsql]# ls
bin data include lib share
5 配置环境变量
[postgres@cjcos ~]$ vim .bash_profile
export PGHOME=/usr/local/pgsql
export PGDATA=/usr/local/pgsql/data
PATH=$PATH:$HOME/bin:$PGHOME/bin
[postgres@cjcos ~]$ source .bash_profile
6 使用initdb初使用化数据库
[postgres@cjcos bin]$ ./initdb -D /usr/local/pgsql/data
[root@cjcos data]# pwd
/usr/local/pgsql/data
[root@cjcos data]# ls
base pg_hba.conf pg_notify pg_stat_tmp pg_twophase postgresql.conf
global pg_ident.conf pg_serial pg_subtrans PG_VERSION
pg_clog pg_multixact pg_snapshots pg_tblspc pg_xlog
7 修改参数
[root@cjcos data]# vim postgresql.conf
#listen_addresses = 'localhost' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
#port = 5432 # (change requires restart)
listen_addresses = '*'
[root@cjcos data]# vim pg_hba.conf
# IPv4 local connections:
host all all 0.0.0.0/0 trust
host all all 127.0.0.1/32 trust
8 启动数据库
[postgres@cjcos bin]$ ./pg_ctl -D /usr/local/pgsql/data -l logfile start
waiting for server to start.... done
server started
9 登录数据库
[postgres@cjcos bin]$ ./psql
psql (12.2)
Type "help" for help.
postgres=# select current_setting('server_version_num');
current_setting
-----------------
120002
(1 row)
10 问题汇总:
问题一:configure: error: readline library not found
问题原因:没有安装readline-devel
解决方案:通过yum安装readline-devel
过程如下:
[postgres@cjcos postgresql-12.2]$ ./configure --prefix=/usr/local/pgsql
......
checking for library containing readline... no
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.
[root@cjcos pgsql]# rpm -qa | grep readline
readline-6.2-10.el7.x86_64
[root@cjcos pgsql]# yum search readline
挂载镜像
[root@cjcos yum.repos.d]# mount /package/V975367-01.iso /mnt -o loop
配置本地yum
[root@cjcos yum.repos.d]# cat yum.repo
[Oralin7u5]
name=local yum
baseurl=file:///mnt
gpgcheck=0
enabled=1
安装readline-devel
[root@cjcos pgsql]# yum -y install -y readline-devel
同时安装其他依赖包
[root@cjcos yum.repos.d]# yum -y install perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake
问题二:postgresql启动报错版本不兼容
问题原因:在安装postgresql12.2之前,操作系统上已经默认安装了一个9.2版本的pg。
解决方案:卸载pg9.2,重新初始化数据库。
过程如下:
[postgres@cjcos bin]$ ./pg_ctl -D /usr/local/pgsql/data -l logfile start
......
2020-04-02 14:43:25.405 CST [27701] FATAL: database files are incompatible with server
2020-04-02 14:43:25.405 CST [27701] DETAIL: The data directory was initialized by PostgreSQL version 9.2, which is not compatible with this version 12.2.
stopped waiting
pg_ctl: could not start server
Examine the log output.
[root@cjcos ~]# rpm -qa|grep postgre
postgresql-docs-9.2.23-3.el7_4.x86_64
postgresql-9.2.23-3.el7_4.x86_64
postgresql-libs-9.2.23-3.el7_4.x86_64
postgresql-server-9.2.23-3.el7_4.x86_64
[root@cjcos ~]# rpm -e postgresql-docs-9.2.23-3.el7_4.x86_64
[root@cjcos ~]# rpm -e postgresql-9.2.23-3.el7_4.x86_64 --nodeps
[root@cjcos ~]# rpm -e postgresql-libs-9.2.23-3.el7_4.x86_64 --nodeps
[root@cjcos ~]# rpm -e postgresql-server-9.2.23-3.el7_4.x86_64
[postgres@cjcos bin]$ ./initdb -D /usr/local/pgsql/data
[postgres@cjcos bin]$ ./pg_ctl -D /usr/local/pgsql/data -l logfile start
更多数据库相关学习资料,可以查看我的ITPUB博客,网名chenoracle:
http://blog.itpub.net/29785807/
发表评论
暂时没有评论,来抢沙发吧~