当前位置: 首页 > news >正文

MacM1Pro Parallels19.1.0 CentOS7.9 Install PostgrepSQL

相关阅读
MacM1Pro安装 Parallels Desktop 19.1.0 https://blog.csdn.net/qq_41594280/article/details/135420241
MacM1Pro Parallels安装Parallels Tools https://blog.csdn.net/qq_41594280/article/details/135398780
MacM1Pro Parallels安装CentOS7.9 https://blog.csdn.net/qq_41594280/article/details/135420461

一、安装 PostgreSQL

yum install -y wget vim
wget https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-aarch64/pgdg-redhat-repo-latest.noarch.rpm --no-check-certificate
yum install -y postgresql-server.aarch64

安装

二、初始化 PostgreSQL 数据库

postgresql-setup initdb
Initializing database ... OK

三、启动 PostgreSQL 服务

# 启动 PostgreSQL 服务 && 设置 PostgreSQL 在系统启动时自动启动
systemctl enable postgresql && systemctl start postgresql

四、配置访问权限

注: 默认情况下,PostgreSQL 配置为仅本地访问。如果你需要从其他机器访问 PostgreSQL 数据库,需要编辑 PostgreSQL 配置文件。

4.1 允许所有地址的连接

vim /var/lib/pgsql/data/postgresql.conf# 内容修改BEGIN#listen_addresses = 'localhost'         # what IP address(es) to listen on;
listen_addresses = '*'# 内容修改END

4.2 配置客户端认证方式

vim /var/lib/pgsql/data/pg_hba.conf# 内容追加BEGIN
host    all             all             0.0.0.0/0               md5
# 内容追加END# 重启服务
systemctl restart postgresql

五、设置 PostgreSQL 密码

sudo -u postgres psql
ALTER USER postgres WITH PASSWORD '123456';
[root@db ~]# psql -U postgres
psql: 致命错误:  对用户"postgres"的对等认证失败

原因: PostgresQL 连接时的默认认证方式为 peer,PostgresQL 会从操作系统内核中获取当前的用户名(SSH的登录用户)并且作为允许连接的用户名进行认证,这种方式仅仅适用于本地连接

# 将认证方式改为md5
vim /var/lib/pgsql/data/pg_hba.conf

在这里插入图片描述

六、连接测试

systemctl restart postgresql# 连接提示: Connection to 10.211.55.37:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.Connection refusedConnection refused

解决

# 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld

在这里插入图片描述

记录

# 退出是 \q
postgres=# \q# 安装扩展插件
sudo yum install pgvector
# 是对应数据库支持此插件
CREATE EXTENSION vector;
# 创建带向量类型的表并查询
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]');
SELECT * FROM items ORDER BY embedding <-> '[3,1,2]' LIMIT 5;# postgres 不在 sudoers 文件中。此事将被报告
[root@db ~]# ll /etc/sudoers
-r--r-----. 1 root root 4328 121 09:03 /etc/sudoers
[root@db ~]# chmod u+w /etc/sudoers
[root@db ~]# vi /etc/sudoers
# 内容BEGIN
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
postgres        ALL=(ALL)       ALL # 新增
# 内容END
# 恢复权限
[root@db ~]# chmod 440 /etc/sudoers
# 新建表空间
CREATE TABLESPACE zhinian_pg_demo LOCATION '/var/lib/pgsql/data';
# 为数据库指定默认表空间
ALTER DATABASE name SET TABLESPACE new_tablespace;
# 查看临时表空间
show temp_tablespaces;CREATE TABLESPACE zhinian_pg_demo LOCATION '/var/lib/pgsql/data';
CREATE TABLE test_tsp(id int, name varchar(50)) TABLESPACE zhinian_pg_demo;
INSERT INTO test_tsp(id,name) VALUES (1, '王飞飞');  
SELECT * FROM test_tsp;
CREATE TABLE test_tsp_new(id int, address varchar(255), name varchar(50)
) TABLESPACE zhinian_pg_demo;INSERT INTO test_tsp_new (id, address, name)
SELECT id, null, name
FROM test_tsp;DROP TABLE test_tsp;
ALTER TABLE test_tsp_new RENAME TO test_tsp;
SELECT * FROM test_tsp;
http://www.lryc.cn/news/285347.html

相关文章:

  • Golang 中如何实现 Set
  • 记录一下uniapp 集成腾讯im特别卡(已解决)
  • React16源码: React中的updateHostRoot的源码实现
  • Template -- React
  • HTML 入门手册(一)
  • GPT帮我快速解决工作上的问题案例
  • Day32- 贪心算法part06
  • .NetCore Flurl.Http 升级到4.0后 https 无法建立SSL连接
  • 【每周AI简讯】GPT-5将有指数级提升,GPT Store正式上线
  • QT上位机开发(MFC vs QT)
  • 线性代数:矩阵的定义
  • k8s 使用cert-manager证书管理自签
  • SpringSecurity+JWT前后端分离架构登录认证
  • 笔试面试题——二叉树进阶(一)
  • Java反射示例
  • 【WinForm.NET开发】实现使用后台操作的窗体
  • 【操作系统和计网从入门到深入】(四)基础IO和文件系统
  • 四.Winform使用Webview2加载本地HTML页面并互相通信
  • 如何有效清理您的Python环境:清除Pip缓存
  • Jira 母公司全面停服 Server 产品,用户如何迁移至极狐GitLab
  • Docker安装配置OnlyOffice
  • 启动低轨道卫星LEO通讯产业与6G 3GPP NTN标准
  • PICO Developer Center 创建和调试 ADB 命令
  • 【VRTK】【PICO】如何快速创建一个用VRTK开发的PICO项目
  • 国产操作系统:VirtualBox安装openKylin-1.0.1虚拟机并配置网络
  • 本地git切换地区后,无法使用ssh访问github 22端口解决方案
  • Chat2DB:AI赋能的多数据库客户端工具,开源领航未来数据库管理
  • SQL Server修改数据字段名的方法
  • Flutter编译报错Connection timed out: connect
  • PG DBA培训26:PostgreSQL运维诊断与监控分析