合 Linux环境下PG 14的安装部署
安装 PostgreSQL 14
常用方法
下载PG
https://yum.postgresql.org/rpmchart.php
https://yum.postgresql.org/14/redhat/rhel-7-x86_64/repoview/postgresqldbserver14.group.html
https://www.postgresql.org/ftp/source/
打开 PostgreSQL 官网 https://www.postgresql.org/,点击菜单栏上的 Download ,可以看到这里包含了很多平台的安装包,包括 Linux、Windows、Mac OS等 ;也可以直接访问:https://www.postgresql.org/download/ 进行下载。
yum在线安装
https://www.postgresql.org/download
https://yum.postgresql.org/repopackages.php
文档:https://www.postgresql.org/download/linux/redhat/
rpm下载:https://yum.postgresql.org/rpmchart/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | docker rm -f lhrpgccc docker run -d --name lhrpgccc -h lhrpgccc \ -p 25432-25439:5432-5439 \ -v /sys/fs/cgroup:/sys/fs/cgroup \ --privileged=true lhrbest/lhrcentos76:8.8 \ /usr/sbin/init docker exec -it lhrpgccc bash -- 一些依赖包 yum install -y cmake make gcc zlib zlib-devel gcc-c++ perl readline readline-devel \ python36 tcl openssl ncurses-devel openldap pam flex -- 删除已存在的PG yum remove -y postgresql* && rm -rf /var/lib/pgsql && rm -rf /usr/pgsql* && userdel -r postgres && groupdel postgres yum install -y sysbench -- 安装yum源 yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm # yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-6-x86_64/pgdg-redhat-repo-latest.noarch.rpm yum repolist all | grep pgdg yum repolist enabled | grep pgdg -- 安装pg,注意:postgresql14-contrib是安装插件的 yum install -y postgresql14 postgresql14-server postgresql14-libs postgresql14-contrib -- 验证 [root@lhrpgccc /]# rpm -aq| grep postgres postgresql14-14.2-1PGDG.rhel7.x86_64 postgresql14-contrib-14.2-1PGDG.rhel7.x86_64 postgresql14-libs-14.2-1PGDG.rhel7.x86_64 postgresql14-server-14.2-1PGDG.rhel7.x86_64 -- 环境变量 echo "export PATH=/usr/pgsql-14/bin:$PATH" >> /etc/profile -- 初始化PG /usr/pgsql-14/bin/postgresql-14-setup initdb systemctl enable postgresql-14 systemctl start postgresql-14 systemctl status postgresql-14 -- 本地登陆 su - postgres psql -- 安装插件 create extension pageinspect; create extension pg_stat_statements; select * from pg_extension ; select * from pg_available_extensions order by name; -- 修改postgres密码 alter user postgres with encrypted password 'lhr'; 或 \password select * from pg_tables limit 10; select version(); firewall-cmd --add-port=5432/tcp --permanent firewall-cmd --reload firewall-cmd --list-port -- 配置允许PG远程登录,注意版本: cat >> /var/lib/pgsql/14/data/postgresql.conf <<"EOF" listen_addresses = '*' port=5432 unix_socket_directories='/var/lib/pgsql/14/data' logging_collector = on log_directory = 'pg_log' log_filename = 'postgresql-%a.log' log_truncate_on_rotation = on EOF cat > /var/lib/pgsql/14/data/pg_hba.conf << EOF # TYPE DATABASE USER ADDRESS METHOD host all all 0.0.0.0/0 trust EOF systemctl restart postgresql-14 -- 远程登陆 psql -U postgres -h 192.168.66.35 -d postgres -p25432 -- 从Postgresql 9.2开始,还可以使用URI格式进行连接:psql postgresql://myuser:mypasswd@myhost:5432/mydb psql postgresql://postgres:lhr@192.168.66.35:25432/postgres \l CREATE DATABASE lhrdb WITH OWNER=postgres ENCODING='UTF-8'; \c lhrdb create table student ( id integer not null, name character(32), number char(5), constraint student_pkey primary key (id) ); \d student INSERT INTO student (id, name, number) VALUES (1, '张三', '1023'); SELECT * FROM student WHERE id=1; |
其中-h参数指定服务器地址,默认为127.0.0.1,默认不指定即可,-d指定连接之后选中的数据库,默认也是postgres,-U指定用户,默认是当前用户,-p 指定端口号,默认是"5432",其它更多的参数选项可以执行: ./bin/psql --help 查看
docker安装
Docker Hub的官网地址:https://hub.docker.com/_/postgres
GitHub的地址:https://github.com/docker-library/postgres