百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 编程字典 > 正文

postgresql数据库安装

toyiye 2024-06-21 12:23 9 浏览 0 评论

一、 配置linux环境

yum install -y wget  # 安装wget
# 配置阿里云镜像源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 这个镜像同样适用于AnolisOS系统
yum clean all && yum makecache
yum install -y lrzsz # 安装上传下载工具 
yum install -y tmux
yum install -y lsof
yum install -y net-tools
yum install -y tar

二、安装数据库

# 安装数据库安装环境
yum install -y perl-ExtUtils-Embed readline-devel zlib-devel pam-devel libxml2-devel libxslt-devel openldap-devel python-devel gcc-c++ openssl-devel cmake gcc gcc-c++ make
# 解压
tar -zxvf postgresql-14.2.tar.gz 
# 创建数据目录
mkdir -p /usr/local/pgsql/data
# postgres创建用户
groupadd postgres
useradd -g postgres postgres
id postgres
# uid=1001(postgres) gid=1001(postgres) 组=1001(postgres)
# 安装数据库
./configure --prefix=/usr/local/pgsql/
make && make istall
chown postgres -R /usr/local/pgsql
chown postgres.postgres -R /usr/local/pgsql/data

选项

描述

–prefix=prefix

安装到prefix指向的目录;默认为/usr/local/pgsql

–bindir=dir

安装应用程序到dir;默认为prefix/bin

–with-docdir=dir

安装文档到dir;默认为prefix/doc

–with-pgport=port

设置默认的服务器端网络连接服务TCP端口号

–with-tcl

为服务端提供Tcl存储过程支持

–with-perl

为服务端提供Perl存储过程支持

–with-python

为服务端提供Python存储过程支持

三、配置环境变量

su -l postgres
vi .bash_profil
    export PGHOME=/usr/local/pgsql/
    export PGDATA=/usr/local/pgsql/data
    PATH=$PATH:$PGHOME/bin:$PGDATA/bin
source .bash_profile

四、initdb初始化数据库

[postgres@localhost ~]$ initdb
The files belonging to this database system will be owned by user "postgres".
This user must also own the server process.

The database cluster will be initialized with locale "zh_CN.UTF-8".
The default database encoding has accordingly been set to "UTF8".
initdb: could not find suitable text search configuration for locale "zh_CN.UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

fixing permissions on existing directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting dynamic shared memory implementation ... posix
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting default time zone ... Asia/Shanghai
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

initdb: warning: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    pg_ctl -D /usr/local/pgsql/data -l logfile start
    
[postgres@localhost data]$ cd /usr/local/pgsql/data
[postgres@localhost data]$ ls
base          pg_hba.conf    pg_notify     pg_stat      pg_twophase  postgresql.auto.conf
global        pg_ident.conf  pg_replslot   pg_stat_tmp  PG_VERSION   postgresql.conf
pg_commit_ts  pg_logical     pg_serial     pg_subtrans  pg_wal
pg_dynshmem   pg_multixact   pg_snapshots  pg_tblspc    pg_xact

五、修改配合文件并启动数据库

修改/pgsql/postgresql/data目录下的两个文件。

postgresql.conf 配置PostgreSQL数据库服务器的相应的参数。

pg_hba.conf 配置对数据库的访问权限。

# 修改配置文件
vi postgresql.conf
    listen_addresses = '*' 
vi pg_hba.conf
    # IPv4 local connections:
    host    all             all             0.0.0.0/0               trust
    host    all             all             127.0.0.1/32            trust
    
# 启动数据库
[postgres@localhost bin]$ postgres -D /usr/local/pgsql/data >logfile 2>&1 &
[1] 14608
# 查看进程
[postgres@localhost bin]$ ps -ef |grep 14608
postgres   14608   14542  0 23:28 pts/0    00:00:00 postgres -D /usr/local/pgsql/data
postgres   14610   14608  0 23:28 ?        00:00:00 postgres: checkpointer 
postgres   14611   14608  0 23:28 ?        00:00:00 postgres: background writer 
postgres   14612   14608  0 23:28 ?        00:00:00 postgres: walwriter 
postgres   14613   14608  0 23:28 ?        00:00:00 postgres: autovacuum launcher 
postgres   14614   14608  0 23:28 ?        00:00:00 postgres: stats collector 
postgres   14615   14608  0 23:28 ?        00:00:00 postgres: logical replication launcher 
postgres   14619   14542  0 23:29 pts/0    00:00:00 grep --color=auto 14608
# 查看端口
[postgres@localhost bin]$ netstat -tunlp|grep 5432
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      14608/postgres      
tcp6       0      0 :::5432                 :::*                    LISTEN      14608/postgres   

# 连接数据库测试
[postgres@localhost bin]$ createdb test  # 创建test库
[postgres@localhost bin]$ psql test # 进入数据库
psql (14.2)
Type "help" for help.

test=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 test      | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
(4 rows)

test=# 

# 数据库重启
pg_ctl restart -D /usr/local/pgsql/data
# 数据库停止
pg_ctl stop -D /usr/local/pgsql/data

六、测试

相关推荐

Qt开发,使用Qt for Python还是Qt C++ Qt开发,使用Qt for

Qt开发使用QtforPython还是QtC++?1.早些年写过一个PyQt5的项目,最近几年重构成QtC++了,其中有个人原因,如早期代码写得烂,...

最简单方法!!用python生成动态条形图

最近非常流行动态条形图,在B站等视频网站上,此类视频经常会有上百万的播放量,今天我们通过第三方库:bar_chart_race(0.2版本)来实现动态条形图的生成;生成的效果如图:问题:...

Asterisk通道和ARI接口的通信(aau通道数)

Asterisk通道和ARI详解什么是通道Asterisk中,通道是介于终端和Asterisk自己本身的一个通信媒介。它包含了所有相关信息传递到终端,或者从终端传递到Asterisk服务器端。这些信...

Python GUI-长链转短链(长链接转化成短链接java)

当我们要分享某一个链接给别人,或是要把某个链接放入帖子中时,如果链接太长,则会占用大量空间,而且很不美观。这时候,我们可以结束长链转短链工具进行转换。当然可以直接搜索在线的网站进行转换,但我们可以借此...

Python 的hash 函数(python的hash函数)

今天在看python的hash函数源码的时候,发现针对不同的数据类型python实现了不同的hash函数,今天简单介绍源码中提到的hash函数。(https://github.com/pyth...

8款Python GUI开源框架,谁才是你的菜?

作为Python开发者,你迟早都会用到图形用户界面来开发应用。本文千锋武汉Python培训小编将推荐一些PythonGUI框架,希望对你有所帮助。1、Python的UI开发工具包Kivy...

python适合开发桌面软件吗?(python可不可以开发桌面应用软件)

其实Python/Java/PHP都不适合用来做桌面开发,Java还是有几个比较成熟的产品的,比如大名鼎鼎的Java集成开发环境IntelliJIDEA、Eclipse就是用Java开发的,不过PH...

CryptoChat:一款功能强大的纯Python消息加密安全传输工具

关于CryptoChatCryptoChat是一款功能强大的纯Python消息加密安全传输工具,该工具专为安全研究专家、渗透测试人员和红蓝队专家设计,该工具可以完全保证数据传输中的隐私安全。该工具建立...

为什么都说Python简单,但我觉得难?

Python普遍被大家认为是编程语言中比较简单的一种,但有一位电子信息的学生说自己已经学了C语言,但仍然觉得Python挺难的,感觉有很多疑问,像迭代器、装饰器什么的……所以他提出疑问:Python真...

蓝牙电话-关联FreeSwitch中继SIP账号通过Rest接口

蓝牙电话-关联FreeSwitch中继SIP账号通过Rest接口前言上一篇章《蓝牙电话-与FreeSwitch服务器和UA坐席的通话.docx》中,我们使用开源的B2B-UA当中经典的FreeSWIT...

技术分享|Sip与WebRTC互通-SRProxy开源库讲解

SRProxy介绍目前WebRTC协议跟SIP协议互通场景主要运用在企业呼叫中心、企业内部通信、电话会议(PSTN)、智能门禁等场景,要想让WebRTC与SIP互通,要解决两个层面的...

全网第N篇SIP协议之GB28181注册 JAVA版本

鉴于网上大部分关于SIP注册服务器编写都是C/C++/python,故开此贴,JAVA实现也贴出分享GB28181定义了了基于SIP架构的视频监控互联规范,而对于多数私有协议实现的监控系统...

「linux专栏」top命令用法详解,再也不怕看不懂top了

在linux系统中,我们经常使用到的一个命令就是top,它主要是用来显示系统运行中所有的进程和进程对应资源的使用等信息,所有的用户都可以使用top命令。top命令内容量丰富,可令使用者头疼的是无法全部...

Linux 中借助 perf 对 php 程序模拟CPU高的案例分析

导语本文是一篇Linux借助工具分析CPU高的优化案例,没有任何干货内容,很详细的展示了优化CPU高的具体步骤,非常适合初中级读者阅读!...

centos漏洞处理方法(centos podman)

centos服务器最近有诸多漏洞,修复命令及对应的漏洞整理后,分享给大家RHSA-2020:1176-低危:avahi安全更新yumupdateavahi-libsRHSA-2017:326...

取消回复欢迎 发表评论:

请填写验证码