当前位置:网站首页>使用yum来安装PostgreSQL13.3数据库
使用yum来安装PostgreSQL13.3数据库
2022-07-06 16:23:00 【华为云】

1、安装概述
PG安装方法很多,和MySQL类似,给用户提供很大的选择空间。如:RPM包安装(在线、离线)、源码编译安装、系统自带、二进制、NDB安装等。
https://yum.postgresql.org/rpmchart.php
https://yum.postgresql.org/11/redhat/rhel-6-x86_64/repoview/postgresqldbserver11.group.html
https://www.postgresql.org/ftp/source/
打开 PostgreSQL 官网 https://www.postgresql.org/,点击菜单栏上的Download ,可以看到这里包含了很多平台的安装包,包括 Linux、Windows、Mac OS等 。
各个安装包:https://www.postgresql.org/ftp/source/
Linux 我们可以看到支持 Ubuntu 和 Red Hat 等各个平台,点击具体的平台链接,即可查看安装方法:

点击上图中的 file browser,我们还能下载 PostgreSQL 最新的源码。

下载地址:
https://www.postgresql.org/download
https://yum.postgresql.org/repopackages.php
文档:https://www.postgresql.org/download/linux/redhat/
rpm下载:https://yum.postgresql.org/rpmchart/
2、yum在线安装
-- 一些依赖包yum install -y cmake make gcc zlib gcc-c++ perl readline readline-devel zlib zlib-devel \perl python36 tcl openssl ncurses-devel openldap pam-- 删除已存在的PGyum remove -y postgresql* && rm -rf /var/lib/pgsql && rm -rf /usr/pgsql* && userdel -r postgres && groupdel postgresyum 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.rpmyum repolist all | grep pgdgyum repolist enabled | grep pgdg-- 安装pgyum install -y postgresql13 postgresql13-server postgresql13-contrib postgresql13-libs# yum install -y postgresql9.6 postgresql9.6-server# yum install postgresql10-server postgresql10-contrib postgresql10 postgresql10.x86_64-- 验证[root@lhrpg /]# rpm -aq| grep postgrespostgresql13-server-13.3-1PGDG.rhel7.x86_64postgresql13-13.3-1PGDG.rhel7.x86_64postgresql13-libs-13.3-1PGDG.rhel7.x86_64postgresql13-contrib-13.3-1PGDG.rhel7.x86_64-- 环境变量echo "export PATH=/usr/pgsql-13/bin:$PATH" >> /etc/profile3、初始化PG,并启动PG
/usr/pgsql-13/bin/postgresql-13-setup initdbsystemctl enable postgresql-13systemctl start postgresql-13systemctl status postgresql-134、修改密码
-- 本地登陆su - postgrespsql-- 安装插件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'; 或 \passwordselect * from pg_tables;select version();5、开放防火墙
-- 开放防火墙firewall-cmd --add-port=5432/tcp --permanentfirewall-cmd --reloadfirewall-cmd --list-port6、配置允许PG远程登录
-- 配置允许PG远程登录,注意版本:cat >> /var/lib/pgsql/13/data/postgresql.conf <<"EOF"listen_addresses = '*'port=5432unix_socket_directories='/var/lib/pgsql/13/data'logging_collector = onlog_directory = 'pg_log'log_filename = 'postgresql-%a.log'log_truncate_on_rotation = onEOFcat << EOF > /var/lib/pgsql/13/data/pg_hba.conf# TYPE DATABASE USER ADDRESS METHODlocal all all trusthost all all ::1/128 trusthost all all 127.0.0.1/32 trusthost all all 0.0.0.0/0 md5host replication all 0.0.0.0/0 md5EOFsystemctl restart postgresql-137、登陆测试
-- 远程登陆psql -U postgres -h 192.168.66.35 -d postgres -p54327-- 从Postgresql 9.2开始,还可以使用URI格式进行远程连接:psql postgresql://myuser:[email protected]:5432/mydbpsql postgresql://postgres:[email protected]:54327/postgres其中-h参数指定服务器地址,默认为127.0.0.1,默认不指定即可,-d指定连接之后选中的数据库,默认也是postgres,-U指定用户,默认是当前用户,-p 指定端口号,默认是"5432",其它更多的参数选项可以执行: ./bin/psql --help 查看。
C:\Users\lhrxxt>psql -U postgres -h 192.168.66.35 -d postgres -p54327Password for user postgres:psql (13.3)Type "help" for help.postgres=# select version(); version------------------------------------------------------------------------------------------------------------------ PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit(1 row)postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges-----------+----------+----------+-------------------+-------------------+----------------------- postgres | postgres | UTF8 | Chinese_China.936 | Chinese_China.936 | template0 | postgres | UTF8 | Chinese_China.936 | Chinese_China.936 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | Chinese_China.936 | Chinese_China.936 | =c/postgres + | | | | | postgres=CTc/postgres(3 rows)postgres=# CREATE DATABASE lhrdb WITH OWNER=postgres ENCODING='UTF-8';CREATE DATABASEpostgres=# \c lhrdbYou are now connected to database "lhrdb" as user "postgres".lhrdb=#lhrdb=# create table student (lhrdb(# id integer not null,lhrdb(# name character(32),lhrdb(# number char(5),lhrdb(# constraint student_pkey primary key (id)lhrdb(# );CREATE TABLElhrdb=#lhrdb=# \d student Table "public.student" Column | Type | Collation | Nullable | Default--------+---------------+-----------+----------+--------- id | integer | | not null | name | character(32) | | | number | character(5) | | |Indexes: "student_pkey" PRIMARY KEY, btree (id)lhrdb=#lhrdb=# INSERT INTO student (id, name, number) VALUES (1, '张三', '1023');INSERT 0 1lhrdb=# SELECT * FROM student WHERE id=1; id | name | number----+------------------------------------+-------- 1 | 张三 | 1023(1 row)8、配置环境变量
mkdir -p /home/postgreschown postgres.postgres /home/postgres -Rsed -i 's|/var/lib/pgsql|/home/postgres|' /etc/passwdecho "lhr" |passwd --stdin postgrescat > /home/postgres/.bash_profile <<"EOF"export PGPORT=5432export PGHOME=/usr/pgsql-13export PGDATA=/var/lib/pgsql/13/dataexport PATH=$PGHOME/bin:$PATHexport MANPATH=$PGHOME/share/man:$MANPATHexport LANG=en_US.UTF-8export DATE='date +"%Y%m%d%H%M"'export LD_LIBRARY_PATH=$PGHOME/lib:$LD_LIBRARY_PATHexport PGHOST=$PGDATAexport PGUSER=postgresexport PGPASSWORD=lhrexport PGDATABASE=postgresexport PS1="[\[email protected]\h \W]\$ "alias psql='rlwrap psql' EOFchown postgres.postgres /home/postgres/.bash_profile安装配置完成,若有不懂,可以私聊麦老师。
边栏推荐
- SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
- App general function test cases
- Why is bat still addicted to 996 when the four-day working system is being tried out in Britain?
- leetcode:236. 二叉树的最近公共祖先
- The intranet penetrates the zerotier extranet (mobile phone, computer, etc.) to access intranet devices (raspberry pie, NAS, computer, etc.)
- Wasserstein slim gain with gradient poverty (wsgain-gp) introduction and code implementation -- missing data filling based on generated countermeasure network
- koa2对Json数组增删改查
- 新手问个问题,我现在是单机部署的,提交了一个sql job运行正常,如果我重启了服务job就没了又得
- I've been laid off, and I'll lose money for everything. The days when I once made a monthly salary of 20000 are not coming back
- The same job has two sources, and the same link has different database accounts. Why is the database list found in the second link the first account
猜你喜欢

What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?

The largest single investment in the history of Dachen was IPO today

MATLIB reads data from excel table and draws function image

11 preparations for Web3 and Decentralization for traditional enterprises
![[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code](/img/47/741b89d94a2b0003937f32bdedfa19.png)
[communication] optimal power allocation in the uplink of two-layer wireless femtocell network with matlab code

STM32通过串口进入和唤醒停止模式

AI金榜题名时,MLPerf榜单的份量究竟有多重?

The problem of ASP reading Oracle Database

《数字经济全景白皮书》保险数字化篇 重磅发布

DAY THREE
随机推荐
在docker中快速使用各个版本的PostgreSQL数据库
编译logisim
基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
The intranet penetrates the zerotier extranet (mobile phone, computer, etc.) to access intranet devices (raspberry pie, NAS, computer, etc.)
【OFDM通信】基于深度学习的OFDM系统信号检测附matlab代码
电脑重装系统u盘文件被隐藏要怎么找出来
本地部署 zeppelin 0.10.1
Yaduo Sangu IPO
Laravel8 uses passport authentication to log in and generate a token
The important data in the computer was accidentally deleted by mistake, which can be quickly retrieved by this method
DevOps可以帮助减少技术债务的十种方式
【精品】pinia 基于插件pinia-plugin-persist的 持久化
MySQL implementation of field segmentation from one line to multiple lines of example code
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
How does crmeb mall system help marketing?
【无人机】多无人协同任务分配程序平台含Matlab代码
氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!
《数字经济全景白皮书》保险数字化篇 重磅发布
Résumé des connaissances de gradle
Matplotlib draws a histogram and adds values to the graph