postgresql编译安装

1.软件下载

点击以下链接

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

因为公司电脑在内网没有外网只能选择编译安装,点击File Browser

点击source

下载所需要的版本我这里下载的是10.10

下载tar.bz2或者tar.gz进行下载

2.程序安装

安装依赖

yum install -y make gcc gcc-c++ readline-devel zlib zlib-devel openssl openssl-devel pam pam-devel libxml2 libxml2-devel libxslt libxslt-devel perl-ExtUtils-Embed

解压tar包

tar xvf postgresql-10.10.tar.bz2

cd postgresql-10.10

编译安装到/usr/local/postgresql
./configure --prefix=/usr/local/postgresql --with-pgport=5432 --with-perl --with-python --with-openssl --with-pam --without-ldap --with-libxml --with-libxslt --enable-thread-safety

报错python,这里需要重新安装python

yum install python python-devel

make && make install

数据库初始化

新建用户和数据文件比赋权

useradd postgres

mkdir -p /usr/local/postgresql/data

chown -R postgres.postgres /usr/local/postgresql/data

新建启动项并加入开机启动

cp contrib/start-scripts/linux /etc/init.d/postgresql

chmod +x /etc/init.d/postgresql

chkconfig --add postgresql 

chkconfig postgresql on

以下两个地方要修改为自己安装的postgresql对应的文件夹和data文件夹

初始化数据文件

/usr/local/postgresql/bin/initdb -D /usr/local/postgresql/data/

出现以下表示完成

数据库启动

/etc/init.d/postgresql start

查看数据库是否启动

创建测试数据库

su - postgres

/usr/local/pgsql/bin/createdb test

连接到test数据库

/usr/local/pgsql/bin/psql test

或者可以

su - postgres

psql -u postgres

create database test

至此postgresql安装完成

另外以下为赋权语句和新建数据库语句

猜你喜欢

转载自blog.csdn.net/zetion_3/article/details/113253392