当前位置:网站首页>postgre数据库
postgre数据库
2022-07-22 10:42:00 【roo_1】
一、post数据库安装
1.1 rpm包安装方式
下载rmp的的网址,下载需要安装的4个rmp包,然后安装
rmp包下载网址
yum install -y libicu
yum install -y libicu-devel
rpm -ivh postgresql10-libs-10.19-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-10.19-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-server-10.19-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-devel-10.19-1PGDG.rhel7.x86_64.rpm
1.2 开启远程访问
需要修改两个配置文件
1.修改postgresql.conf
修改成 listen_addresses = ‘*’
2.修改pg_hba.conf
vim /var/lib/pgsql/10/data/pg_hba.conf
在 # IPv4 local connections:下面输入,trust表示不需要密码,md5的话表示需要密码
host all all 192.168.0.1/16 trust
3.重启
systemctl restart postgresql-10
1.3 pg的连接方式
# 远程连接方式1
psql -U postgres -d postgres -h 192.168.0.10 -p 5432
# 远程连接方式2
psql "host=192.168.2.76 port =5432 user = postgres password = Qaz123456! dbname=postgres"
1.4 pg使用shell执行sql
psql "host=192.168.0.123 port =5432 user = treece password =1123 dbname=amt" -f ./XXX.sql
pg使用shell执行sql
参考
二、一键安装pg
21. 安装
参考1.1下载pg文件
tar -zxvf pg10-rpm.tar.gz
cd pg10
# 安装
yum install -y libicu
yum install -y libicu-devel
rpm -ivh postgresql10-libs-10.19-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-10.19-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-server-10.19-1PGDG.rhel7.x86_64.rpm
rpm -ivh postgresql10-devel-10.19-1PGDG.rhel7.x86_64.rpm
# 启动
/usr/pgsql-10/bin/postgresql-10-setup initdb
sudo systemctl start postgresql-10
sudo systemctl enable postgresql-10.service
sleep 1
echo '----------1、postgresql install success !!!----------'
# 修改密码
su - postgres -c "echo \"ALTER USER postgres WITH PASSWORD 'Qaz123456!';\" >> update_password.sql "
su - postgres -c "psql -f ./update_password.sql"
systemctl restart postgresql-10
sleep 1
echo '----------2、postgresql change PASSWORD success!!!----------'
# 开启远程连接
echo "listen_addresses = '*'" >> /var/lib/pgsql/10/data/postgresql.conf
sed -i '/IPv4 local connections:/a\host all all 192.168.0.1/16 md5' /var/lib/pgsql/10/data/pg_hba.conf
sed -i '/IPv4 local connections:/a\host all all 100.0.0.1/8 md5' /var/lib/pgsql/10/data/pg_hba.conf
sed -i '/IPv4 local connections:/a\host all all 172.0.0.1/8 md5' /var/lib/pgsql/10/data/pg_hba.conf
systemctl restart postgresql-10
cp /root/postgres/dts-test.sql /root/postgres/createdatabase.sql /var/lib/pgsql/
sleep 1
echo '----------3、postgresql change conf success!!!----------'
echo '----------4、install done!!!----------'
2.2 安装之后的使用方式
# 创建sql
CREATE DATABASE dtstest1;
\c dtstest1;
CREATE TABLE COMPANY(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 20000.00);
INSERT INTO COMPANY (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Lily', 10, 'California', 40000.00);
CREATE TABLE COMPANY2(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
INSERT INTO COMPANY2 (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 20000.00);
INSERT INTO COMPANY2 (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Lily', 10, 'California', 40000.00);
CREATE DATABASE dtstest2;
\c dtstest2;
CREATE TABLE COMPANY1(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
INSERT INTO COMPANY1 (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 20000.00);
INSERT INTO COMPANY1 (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Lily', 10, 'California', 40000.00);
CREATE TABLE COMPANY2(
ID INT PRIMARY KEY NOT NULL,
NAME TEXT NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR(50),
SALARY REAL
);
INSERT INTO COMPANY2 (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, 'Paul', 32, 'California', 20000.00);
INSERT INTO COMPANY2 (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, 'Lily', 10, 'California', 40000.00);
运行sql
# 安装方法
tar -zxvf postgres-install.tar.gz
cd postgres/
bash install-postgres.sh
# 创建数据
su - postgres -c " psql -f ./dts-test.sql"
su - postgres -c " psql -f ./createdatabase.sql"
# test 连接
ip='192.168.2.76'
psql "host=${ip} port =5432 user = postgres password = Qaz123456! dbname=postgres"
边栏推荐
- 1080 graduate admission (30 points)
- 基于非线性最坏情况分析的电荷缩放 DAC 中电容器的新棋盘放置和尺寸调整方法
- Latex compiles and reports errors in vscode `recipe terminated with error Retry building the project.
- pytorch 动态调整学习率,学习率自动下降,根据loss下降
- 动态内存和静态内存浅析
- Wiring ability of twisted common centroid capacitor array under signal coupling constraints
- Lire attentivement le document DETR et analyser la structure du modèle
- Latex在VSCODE中编译报错`Recipe terminated with error. Retry building the project.
- 【FPGA】:ip核--XADC
- 1053 Path of Equal Weight (30 分)
猜你喜欢
Stack implementation (C language)
Leetcode high frequency question: what is the difference between the combat effectiveness of the two soldiers with the closest combat effectiveness of N soldiers in the challenge arena
面向高性能计算场景的存储系统解决方案
pytorch 动态调整学习率,学习率自动下降,根据loss下降
链栈实现(C语言)
Pytorch不同层设置不同学习率
YOLO v1、v2、v3
Analysis of class parameters in pytoch, source code analysis of in class member function.Parameters (), acquisition of parameter set, registration and assignment of parameters, source code analysis
信号耦合约束下扭曲共质心电容器阵列的布线能力
模拟QQ登陆界面
随机推荐
7-2 rank a linked list (25 points)
Rag summary
【fpga】gtx/gth概述
Latex compiles and reports errors in vscode `recipe terminated with error Retry building the project.
Likeshop100%开源无加密-B2B2C多商户商城系统!!
Parasitic sensing common centroid binary weighted capacitor layout generation integrates layout, wiring, and cell capacitor size
1072 gas station (30 points)
【FPGA】:ip核-DDS
【面试:基础篇03:选择排序】
Monkey 介绍及使用
模拟电路中晶体管阵列的性能感知公共质心布局和布线 ALIGN
使用多种加权方法在 SAR ADC 中放置二进制加权电容阵列
Deformable Detr paper accuracy, and analyze the network model structure
具有非矩形布局1结构的电流镜的梯度灵敏度降低
Automatic generation of common centroid capacitance array with arbitrary capacitance ratio
Image quality assessment
Vscode compares two files
DETR 论文精读,并解析模型结构
1076 forwards on Weibo (30 points)
【FPGA】:aurora核的使用