Postgresql学习笔记-1(debian安装)
- 安装
admin@d19bfec087dc:~$ sudo apt-get install postgresql postgresql-client postgresql-server-dev-all
安装完成后,PostgreSQL默认创建了名为postgres用户,并创建了postgres的Linux系统账户,PostgreSQL的默认数据库是template1,在postgres的系统账户下可以用命令行管理工具psql来管理它。
- 启动postgres服务
admin@d19bfec087dc:~$ sudo /etc/init.d/postgresql start
Starting PostgreSQL 9.4 database server: main.
admin@d19bfec087dc:~$
- 查看是否启动成功
admin@d19bfec087dc:~$ ps -aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 55168 5416 ? Ss 02:23 0:00 /usr/sbin/sshd -D
root 8 0.0 0.0 4328 772 ? Ss 02:23 0:00 sh
root 54 0.0 0.1 91168 3052 ? Ss 02:24 0:00 nginx: master process /usr/sbin/nginx
www-data 55 0.0 0.1 91532 3740 ? S 02:24 0:00 nginx: worker process
www-data 56 0.0 0.1 91532 3740 ? S 02:24 0:00 nginx: worker process
www-data 57 0.0 0.1 91532 3740 ? S 02:24 0:00 nginx: worker process
www-data 58 0.0 0.1 91532 3740 ? S 02:24 0:00 nginx: worker process
postgres 294 0.0 1.0 225108 21380 ? S 02:37 0:00 /usr/lib/postgresql/9.4/bin/postgres -D /var/lib/postgresql/9.4/main -c config_file=/etc/post
postgres 296 0.0 0.2 225108 4236 ? Ss 02:37 0:00 postgres: checkpointer process
postgres 297 0.0 0.2 225108 5872 ? Ss 02:37 0:00 postgres: writer process
postgres 298 0.0 0.2 225108 4236 ? Ss 02:37 0:00 postgres: wal writer process
postgres 299 0.0 0.3 225548 6616 ? Ss 02:37 0:00 postgres: autovacuum launcher process
postgres 300 0.0 0.2 80388 4464 ? Ss 02:37 0:00 postgres: stats collector process
root 346 0.0 0.1 39980 3096 ? S 02:44 0:00 sudo login admin
root 347 0.0 0.1 63300 2820 ? S 02:44 0:00 login
admin 349 0.0 0.1 20208 3240 ? S 02:44 0:00 -bash
admin 392 0.0 0.1 17492 2072 ? R+ 02:51 0:00 ps -aux
admin@d19bfec087dc:~$
- 切换到postgres用户
admin@d19bfec087dc:~$ sudo su postgres
[sudo] password for admin:
postgres@d19bfec087dc:/home/admin$
- 登录数据库
postgres@d19bfec087dc:/home/admin$ psql
psql (9.4.5)
Type "help" for help.
postgres=#
- 显示数据库列表
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+-----------+---------+-------+-----------------------
postgres | postgres | SQL_ASCII | C | C |
template0 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | SQL_ASCII | C | C | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)
postgres=#
- 链接数据库template1
postgres=# \c template1
You are now connected to database "template1" as user "postgres".
template1=#
- 显示数据表
template1=# \dl
Large objects
ID | Owner | Description
----+-------+-------------
(0 rows)
template1=#
- 退出
template1=# \q
postgres@d19bfec087dc:/home/admin$
转载自:https://blog.csdn.net/bluefish_ygz/article/details/50338697