首页 > 数据库 >Linux环境安装postgresql

Linux环境安装postgresql

时间:2024-01-29 11:33:46浏览次数:38  
标签:postgresql postgres database -- data Linux test 安装 schema

一、资源包下载

1.1、官网下载地址

https://www.postgresql.org/ftp/source/

 

1.2 上传安装包,并解压

# .tar.gz后缀:tar -zxvf 文件名
# .tar.xz后缀:tar -Jxvf 文件名
# -C 后面是解压后存放的目录
​
tar -xvf postgresql-15.3.tar.gz -C /data/database/postgresql/package
​
# 重命名
mv 原文件夹名 postgresql
# 软链接
ln -s 文件夹名 postgresql

 

二、配置环境

2.1 安装依赖

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* readline-devel

 

2.2 创建用户组

useradd postgres

 

2.3 创建目录并授权

mkdir -p /data/database/postgres/postgresql15
chown -R postgres:postgres /data/database/postgres

 

2.4 添加环境变量

vim /etc/profile
​
export PATH=/data/database/postgres/postgresql15/bin:$PATH
export PGHOME=/data/database/postgres/postgresql15
export PGDATA=/data/database/postgres/postgresql15/data/
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PGHOME/lib/
export PATH=$PGHOME/bin:$PATH:$HOME/bin
​
#使配置生效
source /etc/profile

 

三、开始安装

3.1 编译

#进入解压目录执行
./configure --prefix=/data/database/postgres/postgresql15/ --with-python --with-libxml --with-libxslt

 

3.2 安装

make && make install

 

3.5 创建data和log目录

 mkdir /data/database/postgres/postgresql15/data
 mkdir data/database/postgres/postgresql15/log

 

3.4 初始化数据库

# 切换为自己前面创建的用户
su postgres
# 初始化数据库操作
/data/database/postgres/postgresql15/bin/initdb -D //data/database/postgres/postgresql15/data/

注:不能在 root 用户下初始数据库,否则会报错

 

3.5 配置远程连接

#修改postgresql.conf
vim data/database/postgres/postgresql15/data/postgresql.conf
# 设置所有ip可连接
listen_addresses = '*' 
# 设置监听端口
port = 5432 
​
#修改pg_hba.conf
# 所有数据库(all)、所有用户(all)、从本机(127.0.0.1/32)均可免密访问(trust)
host    all             all             0.0.0.0/0               trust

 

3.6 启动服务

pg_ctl start -l /usr/local/postgresql/log/pg_server.log

 

3.7 登录数据库

psql -U postgres -d postgres

 

2.8 创建用户

#登录数据库,直接数据即可
psql -U postgres -d postgres
​
#创建数据库
CREATE DATABASE test;
​
#创建名为 zhangsan 的用户,请运行以下命令:
CREATE USER zhangsan WITH PASSWORD '123456';
 
#修改密码
alter user test with password 'password';
​
#授予szja用户 kangkang 数据库的所有权限
grant all privileges on database test to zhangsan;
​
#现在使用 zhangsan 用户登录数据库, 创建名为 test_schema 的 schema
CREATE SCHEMA test_schema;
 
## 删除可以执行如下命令
DROP SCHEMA test_schema;
​
#授予名为 zhangsan 用户对名为 test_schema 的 schema 下表的所有操作权限
GRANT USAGE ON SCHEMA test_schema to zhangsan;
grant all privileges on all tables in schema test_schema to zhangsan;
grant all privileges on all sequences in schema test_schema to zhangsan;
grant select,insert,update,delete on all tables in schema test_schema to zhangsan;

 

四、遇到问题

4.1 无法远程连接

取消了远程访问ip的限制后,还是无法远程访问的问题

可能原因:5432端口未开放

1、直接关闭防火墙

# 关闭防火墙
systemctl stop firewalld
# 开启防火墙
systemctl start firewalld
# 查看防火墙状态
systemctl status firewalld
# 重启防火墙
systemctl restart firewalld

 

2、配置防火墙,开启5432端口

  • 开放5432端口

firewall-cmd --zone=public --add-port=5432/tcp --permanent
  • 关闭5432端口

firewall-cmd --zone=public --remove-port=5432/tcp --permanent 
  • 让配置立即生效

firewall-cmd --reload 
  • 重启防火墙

systemctl restart firewalld
  • 查看已开放的端口

firewall-cmd --list-ports

 

4.2 Nacicat 远程连接报错

 

解决方法1:升级navicat

将navicat升级到16.2以上版本

 

解决方法2:修改dll

找到navicat安装目录,有一个libcc.dll文件

1.备份这个文件

2.进入网站https://hexed.it/ 打开本地的libcc.dll 文件

3.右侧点击搜索,关键词“SELECT DISTINCT datlastsysoid”

4.找到之后,把‘datlastsysoid’这几个字,改成“dattablespace”

5.然后把文件下载回来,放回原处

 

 

 

标签:postgresql,postgres,database,--,data,Linux,test,安装,schema
From: https://www.cnblogs.com/yangjcBlog/p/17994136

相关文章

  • 虚拟环境python3.8安装GDAL包
    网上的方法直接是:pipinstallGDAL‑3.4.1‑cp38‑cp38‑win_amd64.whl但是这个方法不适用于我,因为我的pycharm上面的anaconda是python3.7,但是我创建了一个python3.8的虚拟环境所以需要:1.切换虚拟环境2.导入离线包python3.8对应着的GDAL为:GDAL-3.4.3-cp38-cp38-win_amd6......
  • ubuntu18容器内安装python3.9
    ubuntu18容器内编辑安装python3.9后,pip安装失败问题参考文档https://www.jianshu.com/p/8a17267caf5fhttps://blog.csdn.net/youxijishu/article/details/128885291https://blog.csdn.net/Beyond_F4/article/details/104004626https://zhuanlan.zhihu.com/p/598697953?utm_id=0......
  • Windows 安装 MySQL 5.8 -- 输入3次 密码错误锁定账户
    安装下载地址:https://downloads.mysql.com/archives/installer/需要有.netframework4.5.2及以上版本才能安装MySQL5.8选择自定义安装选择要安装的服务修改安装路径设置ROOT密码,测试错误锁定帐号MySQL8.0.19版本之后,新增了一个功能,支持了输入3次......
  • linux中输出重定向
    介绍任何一个程序在Linux中运行,Linux系统都会为其创建3个已经打开的stream,分别用来输入(0:stdin),输出(1:stdout),打印诊断和错误信息(2:stderr)。通常他们会被连接到用户终端。这3个句柄的类型为指向FILE的指针。可以被fprintf、fread等函数使用,他们在程序开始启动后,stdin,stdo......
  • Linux环境安装MYSQL
    一、卸载MariaDB##查看是否安装rpm-qa|grepmariadb##卸载rpm-e--nodepsmariadb-libs 二、资源包准备2.1官网下载https://dev.mysql.com/downloads/mysql/ 2.2上传安装包,并解压#.tar.gz后缀:tar-zxvf文件名#.tar.xz后缀:tar-Jxvf文件名tar-xvf......
  • linux 每2个小时执行定时任务
    [root@localhost~]#crontab-l0*/2***sh/home/data-integration/run_logintop.sh0*/2***sh/home/data-integration/run_stationtj.sh[root@localhost~]#cat/home/data-integration/run_logintop.sh#!/bin/bashcd/home/data-integrationnohup......
  • 关于Linux内核4.12之前版本中, tcp_tw_recycle开启后NAT环境总是出问题的分析
     问题出现的场景很简单,nat网关下,有几台服务器,需要访问企业内部的某个的API服务器,API服务器上rcycle设置为1(4.12内核版本之前有这个设置,之后这个属性取消了,理论上也不会出现这种问题了),就在NAT下客户端并发量比较大的情况下,出现连接不上的情况(应该是SYN后,没有收到SYNACK,连接被丢......
  • docker安装windows
    声明:文章转载于微信公众号:高等精灵实验室,更多详情请移步原文保姆级:在NAS上使用Docker跑一个Windows系统,支持远程桌面,有点意思!​原创......
  • 寒假学习日志2-spark的安装和配置
    1.在官网下载spark(需要在hadoop安装配置完成后进行)下载的是2.4.0版本的2.将压缩文件放入到linux系统中进行解压 3.安装后,还需要修改Spark的配置文件spark-env.sh 4.验证spark的安装  安装成功5.使用spark-shell ......
  • 【亲测管用】Linux环境下MySQL 8.0重置密码
    这个问题折磨了我有两三个小时了,看了一大堆博客,大多数都不好用,真的怀疑有没有亲自试用过。本文使用的服务器为阿里云的服务器Linux系统,MySQL的版本为8.0。修改密码操作如下,供大家参考:在/etc/my.cnf中添加如下代码,使其支持免密登录[mysqld]skip-grant-tables重启MySQL服......