Progresql数据库安装--安装

--安装progresql数据库
systemctl disable firewalld
systemctl status firewalld
systemctl stop firewalld


--准备工作
yum install epel-release.noarch -y
yum install libzstd.x86_64 -y


# Install the repository RPM:
s
sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm

#
# Install PostgreSQL:
s
sudo yum install -y postgresql15-server

#
# Optionally initialize the database and enable automatic start:
s
sudo /usr/pgsql-15/bin/postgresql-15-setup initdb
s
sudo systemctl enable postgresql-15

sudo systemctl start postgresql-15

systemctl restart postgresql-15


## 使用linux用户postgre登录
s
su - postgres
p
psql -U postgres
p
password
#
# postgres_Q

#
## 查看数据库版本
s
select version();


# 格式 psql -h 主机IP -p 端口 -U 用户名 -W -d 数据库 
# 示例 psql -h 127.0.0.1 -p 5432 -U postgres -d test_db;
psql -h 192.168.3.34 -p5432 -U postgres -d postgres

# 设置密码(自由发挥):postgres
alter user postgres with password 'password';

---配置远程---
#编辑
vim /var/lib/pgsql/15/data/postgresql.conf
修改参数:
listen_addresses = '*'

# 编辑配置
vim /var/lib/pgsql/15/data/pg_hba.conf

# 添加内容
host    all             all              0.0.0.0/0              md5

#重启
sudo systemctl restart postgresql-15

安装7za
yum install p7zip
yum -y install dos2unix

-------------------------------创建外表---------------
create extension file_fdw;
create server file_fdw_server foreign data wrapper file_fdw;
create foreign table passwd (username text,pass text,uid int4,gid int4,gecos text,home text,shell text
) server file_fdw_server
OPTIONS (format 'text', filename '/etc/passwd', delimiter ':', null '');
select * from passwd limit 5


--------------------------------------------------------------------
psql -U 用户名 -d 数据库名 -f 文件名.sql


psql -U 用户名 -d 数据库名 -c "SELECT * FROM 表名;"


psql -h 192.168.3.34 -p5432 -U postgres -d stock -c "insert into dw_stock_base_d select * from dw_stock_base_d_temp; commit;"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值