centos 7 安装postgresql

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

# Install PostgreSQL:
sudo yum install -y postgresql14-server

# Optionally initialize the database and enable automatic start:
sudo /usr/pgsql-14/bin/postgresql-14-setup initdb
sudo systemctl enable postgresql-14
sudo systemctl start postgresql-14
复制代码

连接数据库(postgres用户连接)

复制代码
[root@AY1405261748171252caZ ~]# su - postgres
Last failed login: Sat Nov 13 11:16:40 CST 2021 from 159.89.12.78 on ssh:notty
There were 1238 failed login attempts since the last successful login.
-bash-4.2$
-bash-4.2$ psql
psql (14.1)
Type "help" for help.

postgres=# select version();
version
---------------------------------------------------------------------------------------------------------
PostgreSQL 14.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44), 64-bit
(1 row)
复制代码

创建root用户,如下:

复制代码
[root@AY1405261748171252caZ ~]# su - postgres
Last login: Sat Nov 13 14:54:34 CST 2021 on pts/0
-bash-4.2$ psql -U postgres
psql (14.1)
Type "help" for help.

postgres=# create user root with password 'password';
CREATE ROLE
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to root;
ERROR:  database "mydatabase" does not exist
postgres=# CREATE DATABASE mydatabase;
CREATE DATABASE
postgres=# GRANT ALL PRIVILEGES ON DATABASE mydatabase to root;
GRANT
postgres=# ALTER ROLE root WITH SUPERUSER;
ALTER ROLE
postgres=# \q
-bash-4.2$ 
复制代码

 




posted @   wobzd  阅读(128)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示