相关阅读
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"的对等认证失败
原因:
# 将认证方式改为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 refused Connection 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 1月 21 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;