导入
安装 PostgreSQL
了解如何安装PostgreSQL数据库并验证安装。
在 Linux 上安装 PostgreSQL 数据库的命令
1# 安装 PostgreSQL 软件包 2apt-get update 3apt-get -y install postgresql 4 5# 启动 PostgreSQL 服务 6service postgresql start 7 8# 查看 PostgreSQL 服务状态 9service postgresql status 10 11# 显示当前正在运行的 postgres 进程 12ps ax | grep postgres: 13 14# 切换用户为 postgres 15su postgres 16 17# 连接到 PostgreSQL 服务并进入 SQL 命令输入提示符 18psql 19 20# 退出 psql 终端 21\q
Terminal
1... 2root@educative:/# service postgresql start 3 * Starting PostgreSQL 15 database server 4 ...done. 5root@educative:/# service postgresql status 615/main (port 5432): online 7root@educative:/# ps ax | grep postgres: 8 490 ? Ss 0:00 postgres: 15/main: checkpointer 9 491 ? Ss 0:00 postgres: 15/main: background writer 10 493 ? Ss 0:00 postgres: 15/main: walwriter 11 494 ? Ss 0:00 postgres: 15/main: autovacuum launcher 12 495 ? Ss 0:00 postgres: 15/main: logical replication launcher 13 515 pts/0 S+ 0:00 grep --color=auto postgres: 14root@educative:/# su postgres 15postgres@educative:/$ psql 16psql (15.1 (Ubuntu 15.1-1.pgdg20.04+1)) 17Type "help" for help. 18postgres-# \q 19postgres@educative:/$
PostgreSQL 的目录结构
1├── bin 2├── data 3├── debug_symbols 4├── doc 5├── include 6├── installer 7├── lib 8├── pgAdmin\ 4.app 9├── scripts 10└── share
1SHOW data_directory;
使用 psql 命令行工具连接 PostgreSQL 服务
1psql -h localhost -U postgres -d mydatabase
1SELECT version();
上述命令的输出结果
1version 2PostgreSQL 9.5.25 on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 35.4.0 20160609, 64-bit