更新时间:2022-12-30 10:30:01浏览次数:818+次
如果要在Ubuntu 20.04下安装PostgreSQL数据库,其方法是很简单的,按照以下步骤操作即可成功在Ubuntu 20.04下安装好PostgreSQL。
安装步骤
1、导入存储库签名密钥:
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
2、添加PostgreSQL apt存储库:
echo "deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main" | sudo tee /etc/apt/sources.list.d/pgdg.list
3、更新包列表并安装postgresql软件包:
sudo apt update
sudo apt install postgresql -y
4、安装完成后,使用以下命令设置PostgreSQL管理员用户的密码:
$ sudo passwd postgres
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
然后可以创建数据库和用户,如以下示例:
$ sudo su - postgres
postgres@taiga:~$ createuser taiga
postgres@taiga:~$ psql
psql (12.4 (Ubuntu 12.4-1.pgdg20.04+1))
Type "help" for help.
postgres=# ALTER USER taiga WITH ENCRYPTED password 'StrongPassword';
postgres=# CREATE DATABASE taiga OWNER taiga;
postgres=# \q
postgres@taiga:~$ exit
注:请为taiga用户提供强数据库密码,为StrongPassword,通常情况下,越复杂越安全。
如果是Ubuntu 22.04版本,可参考在Ubuntu 22.04系统上安装PostgreSQL 14的详细步骤。
相关资讯