设为首页 加入收藏

TOP

Debian平台下Postgresql数据库基本操作说明(一)
2015-07-24 10:16:14 来源: 作者: 【 】 浏览:3
Tags:Debian 台下 Postgresql 数据库 基本 操作说明

?

?

?

1 安装postgresql

--使用apt 直接安装:

dave@dave:~/cndba$ sudo apt-get installpostgresql postgresql-client postgresql-server-dev-all -y

?

--查看数据库状态:

postgres@dave:~$ /etc/init.d/postgresql status

Running clusters: 9.1/main

?

--停止:

postgres@dave:~$ /etc/init.d/postgresql stop

[ ok ] Stopping PostgreSQL 9.1 databaseserver: main.

?

--启动:

postgres@dave:~$ /etc/init.d/postgresql start

[ ok ] Starting PostgreSQL 9.1 databaseserver: main.

postgres@dave:~$

?

--查看进程:

postgres@dave:~$ ps -ef|grep postgres

root 9502 9184 0 06:34 pts/2 00:00:00 su - postgres

postgres 9510 9502 0 06:34 pts/2 00:00:00 -su

postgres 9869 1 0 06:52 ? 00:00:00/usr/lib/postgresql/9.1/bin/postgres -D /var/lib/postgresql/9.1/main -cconfig_file=/etc/postgresql/9.1/main/postgresql.conf

postgres 9871 9869 0 06:52 ? 00:00:00 postgres: writer process

postgres 9872 9869 0 06:52 ? 00:00:00 postgres: wal writer process

postgres 9873 9869 0 06:52 ? 00:00:00 postgres: autovacuum launcherprocess

postgres 9874 9869 0 06:52 ? 00:00:00 postgres: stats collectorprocess

postgres 9905 9510 0 06:53 pts/2 00:00:00 ps -ef

postgres 9906 9510 0 06:53 pts/2 00:00:00 grep postgres

postgres@dave:~$

?

--设置开机自启动:

postgres@dave:~$ sudo update-rc.d postgresql start 88 2 3 4 5 . stop 88 0 1 6 .

update-rc.d: using dependency based bootsequencing

postgres@dave:~$

?

第一次安装后,默认生成一个名为postgres的数据库和一个名为postgres的数据库用户。同时还生成了一个名为postgres的Linux系统用户。

?

--修改postgres 用户密码:

dave@dave:~$ sudo passwd postgres

Enter new UNIX password:

Retype new UNIX password:

passwd: password updated successfully

dave@dave:~$

?

2 查看数据库信息

--查看数据库信息:

dave@dave:~$ su - postgres

Password:

postgres@dave:~$ psql

psql (9.1.15)

Type "help" for help.

?

postgres=# help

You are using psql, the command-lineinterface to PostgreSQL.

Type: \copyright for distribution terms

\h for help with SQL commands

\? for help with psql commands

\g or terminate with semicolon to execute query

\q to quit

postgres=#

?

postgres-# \l

List of databases

Name | Owner | Encoding | Collate | Ctype | Access privileges

-----------+----------+----------+-------------+-------------+-----------------------

postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |

template0 | postgres | UTF8 |en_US.UTF-8 | en_US.UTF-8 | =c/postgres +

| | | | | postgres=CTc/postgres

template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |=c/postgres +

| | | | |postgres=CTc/postgres

(3 rows)

?

postgres-#

?

--连接到某个数据库:

postgres-# \c postgres

You are now connected to database"postgres" as user "postgres".

postgres-# \c template1

You are now connected to database"template1" as user "postgres".

template1-#

?

postgres=# \c postgres

You are now connected to database"postgres" as user "postgres".

?

--显示当前的数据库:

postgres=# select current_database();

current_database

------------------

postgres

(1 row)

?

--该命令显示当前的userid:

postgres=# select current_user; 

current_user

--------------

postgres

(1 row)

?

?

--退出操作界面:

template1-# \q

postgres@dave:~$

?

?

3 创建DB对象

?

默认的postgres用户是超级管理员,权限太大,所以一般建议创建一个独立的管理用户。

?

dave@dave:~$ su - postgres

Password:

postgres@dave:~$ psql

psql (9.1.15)

Type "help" for help.

?

--创建数据库用户、数据库,并赋予新用户新数据库的全部权限:

postgres=# create user dave with password'dave';

CREATE ROLE

postgres=# create database cndba;

CREATE DATABASE

postgres=# grant all privileges on databasecndba to dave;

GRANT

postgres=#

?

p

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇SQLServer中DML语句要申请的锁 下一篇T_SQLrowtype类型

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·C/C++ 类模板与模板 (2025-12-27 01:49:52)
·C语言 模板化<templ (2025-12-27 01:49:49)
·C/C++模板类模板与函 (2025-12-27 01:49:46)
·如何理解c语言指针和 (2025-12-27 01:19:11)
·为什么C标准库没有链 (2025-12-27 01:19:08)