--安装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;"