一.rpm的安装方法
1.官网下载
##选择对应版本
https://www.postgresql.org/download/
##Linux centos7
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
##安装pg server
sudo yum install -y postgresql11-server
##初始化
sudo /usr/pgsql-11/bin/postgresql-11-setup initdb
##加入服务和启动pg服务
sudo systemctl enable postgresql-11
sudo systemctl start postgresql-11
二.tar.gz的安装
1.下载
wget https://www.postgresql.org/ftp/source/v11.9/postgresql-11.9.tar.gz
2.解压
tar -zxvf postgresql-11.9.tar.gz
3.创建组和用户
groupadd postgres
useradd postgres
4.创建数据目录
mkdir /data/pg_data/data
mkdir /data/pg_data/log
5.授权
chown -R postgres. pg_data/
chown -R postgres. pgsql
6.环境变量设置
vim /etc/profile
export PGHOME=/usr/local/pgsql/
export PATH=$PGHOME/bin:$PATH
##重新加载
source /etc/profile
7.编译
cd postgresql-11.9/
##指定安装路径./configure --prefix=/data/postgres,默认是/usr/local下
./configure
make && make install
(安装过程如果缺少依赖包错误提示,则安装对应的依赖包)
8.初始化数据库
su postgres
initdb -D /data/pg_data/data -E UTF8
9.启动
sudo -u postgres ./pg_ctl -D /data/pg_data/data/ -l /data/pg_data/log/pg.log start
##查看进程
ps -ef |grep pg
10.登录
pgsql -U postgres -d postgres -h 127.0.0.1 -p 5432
离线安装遇到的问题
##需要安装gcc
checking for gcc… no
checking for cc… no
##需要安装readline-devel
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.
##需要安装zlib
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.
或者
./configure --without-readline --without-zlib
基本概念
- relation:表示表或索引,相当于其他数据库类型table或index
- tuple:表示表中的行,相当于其他数据库类型row
- page:表示磁盘中的数据块
- buffer:表示在内存中的数据块
- schema:模式是数据库中的一个概念,可以将其理解为一个命名空间或目录,不同的模式下可以有相同名称的表,函数等对象而不会产生冲突。
- 模式:一个数据库包含一个或多个模式,模式中又包含了表,函数以及操作符等数据库对象。
- 公共模式:创建一个新的数据库是,postgresql都会为我们自动创建一个名为public模式。schema_name.table_name,通过“.”方式调用模式下的表