安装参考:http://www.postgresql.org/download/linux/ubuntu/

y@y:~$ sudo apt-get install postgresql-9.3  postgresql-client-9.3  postgresql-contrib-9.3 postgresql-server-dev-9.3  pgadmin3 

* Starting PostgreSQL 9.3 database server [ OK ]
正在设置 postgresql-contrib-9.3 (9.3.5-0ubuntu0.14.04.1) ...
Processing triggers for libc-bin (2.19-0ubuntu6) ...

表示安装成功。

配置:

1:使用psql客户端登录

y@y:~$ sudo -u postgres psql
psql (9.3.)
Type "help" for help.

2:修改PostgreSQL默认用户postgres的登录密码

PostgreSQL数据默认会创建一个postgres的数据库用户作为数据库的管理员,密码是随机的,所以这里要修改密码。

postgres=# alter user postgres with password 'postgres';
ALTER ROLE

3:退出PostgreSQL psql客户端

postgres-# \q
could not save history to file "/var/lib/postgresql/.psql_history": 没有那个文件或目录
(重新登录就可以了,由于第一次文件是不存在的)

4:修改linux系统的postgres用户的密码

y@y:~$ sudo passwd -d postgres
passwd:密码过期信息已更改。
y@y:~$ sudo -u postgres passwd
输入新的 UNIX 密码:
重新输入新的 UNIX 密码:
passwd:已成功更新密码

5:修改PostgresSQL数据库配置实现远程访问

y@y:~$ sudo vim /etc/postgresql/9.3/main/postgresql.conf
().监听任何地址访问,修改连接权限
#listen_addresses = ‘localhost’改为 listen_addresses = ‘*’
().启用密码验证
#password_encryption = on改为password_encryption = on
().可访问的用户ip段
y@y:/etc/postgresql/9.3/main$ sudo vim pg_hba.conf
并在文档末尾加上以下内容
# to allow your client visiting postgresql server
host all all 0.0.0.0 0.0.0.0 md5
():重启PostgreSQL数据库
y@y:~$ /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.3 database server * Error: You must run this program as the cluster owner (postgres) or root
[fail]
重启失败,提示需要root权限
y@y:~$ sudo /etc/init.d/postgresql restart
* Restarting PostgreSQL 9.3 database server [ OK ]
y@y:~$

6:管理PostgreSQL用户和数据库

()登录postgre SQL数据库
y@y:~$ sudo psql -U postgres -h 127.0.0.1
Password for user postgres:
()创建新用户test,但不给建数据库的权限
用户名要用双引号,以区分大小写,密码不用
postgres=# create user "test" password 'test' nocreatedb;
CREATE ROLE
()建立数据库,并指定所有者
postgres=# create database "testdb" with owner="test";
CREATE DATABASE ()在外部命令行的管理命令
postgres=# -u postgres createuser -D -P test1
-D该用户没有创建数据库的权利,-P提示输入密码,选择管理类型y/n
postgres-# -u postgres createdb -O test1 db1
-O设定所有者为test1
登录数据库
y@y:~$ psql -U test -d testdb -h 127.0.0.1 -p
Password for user test:
psql (9.3.)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: )
Type "help" for help. testdb=>

7:基本的数据库操作,就是使用一般的SQL语言

# 创建新表
CREATE TABLE user_tbl(name VARCHAR(20), signup_date DATE);
# 插入数据
INSERT INTO user_tbl(name, signup_date) VALUES('张三', '2013-12-22');
# 选择记录
SELECT * FROM user_tbl;
# 更新数据
UPDATE user_tbl set name = '李四' WHERE name = '张三';
# 删除记录
DELETE FROM user_tbl WHERE name = '李四' ;
# 添加栏位
ALTER TABLE user_tbl ADD email VARCHAR(40);
# 更新结构
ALTER TABLE user_tbl ALTER COLUMN signup_date SET NOT NULL;
# 更名栏位
ALTER TABLE user_tbl RENAME COLUMN signup_date TO signup;
# 删除栏位
ALTER TABLE user_tbl DROP COLUMN email;
# 表格更名
ALTER TABLE user_tbl RENAME TO backup_tbl;
# 删除表格
DROP TABLE IF EXISTS backup_tbl;

Ubuntu14.04安装PostpreSQL9.3.5记录的更多相关文章

  1. Ubuntu14.04安装配置web/ftp/tftp/dns服务器

    目录: 1.安装ftp服务器vsftpd --基于tcp,需要帐号密码 2.安装tftp服务器tftpd-hpa,tftp-hpa --udp 3.web服务器--使用Apache2+Mysql+PH ...

  2. Ubuntu14.04安装intel集显驱动

    Ubuntu14.04安装intel集显驱动 标签(空格分隔): ubuntu linux 驱动安装 1.查看本机显卡型号 使用lspci命令来获取PCI接口硬件信息 o@o-pc:~$ lspci ...

  3. Ubuntu14.04安装中文输入法以及解决Gedit中文乱码问题

    1 设置中文显示环境 1. 打开System Settings 2. 打开Personal-> Language Support. 会弹出如下对话框,提示你“语言支持没安装完整”. 点击“Rem ...

  4. Ubuntu14.04安装配置ndnSIM

    Ubuntu14.04安装配置ndnSIM 预环境 Ubuntu14.04官方系统 请先使用sudo apt-get update更新一下源列表 安装步骤 安装boost-lib sudo apt-g ...

  5. Ubuntu14.04 安装QQ国际版wine-qqintl

    Ubuntu14.04安装qq国际版方式: 首先下载,链接为:  https://pan.baidu.com/s/1boPitVD 密码:jp1j 也可去Ubuntu中文的Kylin(优麒麟)官网下载 ...

  6. 一.ubuntu14.04安装、亮度设置、显卡设置等一体化讲解

    一.ubuntu14.04安装 安装步骤很简单的,相信你只要知道并且决定安装ubuntu,你就不会在安装上有问题,下载网址 http://www.ithome.com/html/soft/81539. ...

  7. Ubuntu14.04安装samba

    Ubuntu14.04安装samba 按照惯例,首先介绍Samba.Samba是在Linux系统上实现的SMB(Server Messages Block,信息服务块)协议的一款免费软件.它实现在局域 ...

  8. Ubuntu14.04安装有道词典

    Ubuntu14.04安装有道词典之前要更新系统: sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade 在有道官网下载 ...

  9. ubuntu14.04 安装redis 2.8.9

    ubuntu14.04安装前准备工作,为了保证安装顺利,请先执行apt-get update 然后安装make 和gcc(已安装的可忽略) apt-get install make apt-get i ...

随机推荐

  1. The JRE could not be found.Edit the server and change the JRE location.

    之前更改了了一个较低的jdk的版本看了看一个项目的代码,不知所云,然后再改回来, 混乱之中只要启动Tomcat就出现这种错误,还是无法找到JRE,最后如此解决: 在Windows->Prefer ...

  2. DJANTO之FORM

    文档很仔细,但熟悉要慢慢来~~ from django.shortcuts import render from contact.forms import ContactForm from djang ...

  3. Android 有缓存功能的请求封装接口

    /* * @Company 浙 江 鸿 程 计 算 机 系 统 有 限 公 司 * @URL http://www.zjhcsoft.com * @Address 杭州滨江区伟业路1号 * @Emai ...

  4. WEB打印插件jatoolsPrinter

    为什么选择 jatoolsPrinter 免费版? 支持无预览直接打印 真正免费,不加水印,没有ip或域名限制,不限时间,兼容ie6+ 无须注册,下载即用 提供经过微软数字签名的cab自动安装包,安装 ...

  5. UVa10340.All in All

    题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. hdu 5641 King's Phone(暴力模拟题)

    Problem Description In a military parade, the King sees lots of new things, including an Andriod Pho ...

  7. 表单javascript checkbox全选 反选 全不选

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  8. git错误:fatal: Not a git repository (or any of the parent directories): .git

    git错误:fatal: Not a git repository (or any of the parent directories): .git 我用git add file添加文件时出现这样错误 ...

  9. 函数nvl,nvl2,nullif,coalesce

    NVL: Converts a null value to an actual valueNVL2:If expr1 is not null, NVL2 returns expr2. If expr1 ...

  10. python -序列化

    python中用于序列化的两个模块 json 用于[字符串]和[python基本数据类型]之间进行转换 pickle 用于[python特有的类型] 和 [python基本数据类型]间进行转换 Jso ...