1.postgreSQL介绍:

PostgreSQL是一个功能强大的开源对象关系数据库系统,它使用并扩展了SQL语言,并结合了许多安全存储和扩展最复杂数据工作负载的功能。

2.postgreSQL特点:

免费,开源,高度可扩展性。数据完整性,并发性,可靠性,灾难恢复。安全。

3.postgreSQL安装:

系统环境 ; Ubuntu16.04 LTS

使用源码编译安装postgreSQL:

下载postgreSQL:#wget--no-cookies--no-check-certificatehttps://ftp.postgresql.org/pub/source/v9.5.14/postgresql-9.5.14.tar.gz创建安装的目录:#mkdir/data/{services,packages,untar}-p安装依赖包:#apt-getinstall-ylibreadline6-devlibxslt-devzlib1g-devsystemtap-sdt-devlibxml2-dev解压软件包:#tar-zxvfpostgresql-9.5.14.tar.gz-C/data/untar/#cd/data/untar/postgresql-9.5.14/#./configure--prefix=/data/services/postgresql9\--datarootdir=/data/services/postgresql9/postdata\--with-pgport=5432--with-python--with-libxml\--with-libxslt--without-ldap--enable-thread-safety--enable-dtrace#make&&makeinstall//编译并安装安装完成后的提示:PostgreSQLinstallationcomplete.

设置postgresql共享库搜索路径:

方法1:定义LD_LIBRARY_PATH的变量。#exportLD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/services/postgresql9/lib方法2:添加到共享库文件:#cat/etc/ld.so.conf.d/postgresql.conf/data/services/postgresql9/lib#ldconfig//立即生效

库文件在链接(静态库和共享库)和运行(仅限于使用共享库的程序)时被使用,其搜索路径是在系统中进行设置的。一般 Linux 系统把 /lib 和 /usr/lib 两个目录作为默认的库搜索路径。ldconfig命令的作用就是将 /etc/ld.so.conf.d/*.conf 列出的路径下的库文件缓存到 /etc/ld.so.cache 以供使用。

linux系统添加共享库详解:https://blog.csdn.net/lu_embedded/article/details/56675653

查看共享库:



设置环境变量:

#echo"exportPATH=$PATH:/data/services/postgresql9/bin">>/etc/profile#source/etc/profile//立即生效。


创建postgres账户并设置密码:

#useradd-d/data/services/postgresql9/-Mpostgres#echo-e"123456\n123456"|passwdpostgres更改属主和属组:#chown-Rpostgres.postgres/data/services/postgresql9/

创建数据目录和初始化数据目录:

#mkdir/data/services/postgresql9/data#su-postgres$bin/initdb-D/data/services/postgresql9/data/

修改配置文件:#grep-Ev'^[]*$|^#'/data/services/postgresql9/data/postgresql.confdata_directory='/data/services/postgresql9/data'#数据库安装路径,用于数据存储的目录hba_file='/data/services/postgresql9/data/pg_hba.conf'#基于主机的身份验证文件ident_file='/data/services/postgresql9/data/pg_ident.conf'#用户名称映射的配置文件external_pid_file='/data/services/postgresql9/postgresql.pid'#用于管理程序的额外进程pid文件listen_addresses='*'#指定服务器在哪些TCP/IP地址上监听客户端连接port=5432#监听数据库的TCP端口max_connections=100#最大连接数。unix_socket_directories='/tmp'#监听来自客户端连接的unix域的套接字目录shared_buffers=128MB#设置数据库服务器将使用的共享内存缓冲区量,默认值。dynamic_shared_memory_type=posix#指定服务器使用shm_open分配的POSIX共享内存。log_line_prefix='%t[%p-%l]%q%u@%d'#设置日志输出格式。log_timezone='PRC'#设置数据库日志文件在写日志文件时使用的时区datestyle='iso,ymd'#日期风格,年月日timezone='PRC'#设置服务端和客户端时区。lc_messages='en_US.UTF-8'#系统错误消息的语言。lc_monetary='zh_CN.UTF-8'#设置货币值的显示格式的语言lc_numeric='zh_CN.UTF-8'#设置用于格式化数字的语言。lc_time='zh_CN.UTF-8'#设置用于格式化时间日期的语言。default_text_search_config='pg_catalog.english'#选择文本搜索功能所使用的文本搜索配置。

设置ubuntu16.04下系统的语言和编码设置:

#apt-getinstall-ylanguage-pack-zh-hantlanguage-pack-zh-hanslanguage-selector-gnome#dpkg-reconfigurelocales选择zh_CN.UTF-8和en_US.UTF-8编码。编码配置文件:/var/lib/locales/supported.d/该文件下有三个文件:enzh-hanszh-hant#dpkg-reconfigure--forcelocales强制更新,使设置生效。

启动服务:

$bin/pg_ctl-D/data/services/postgresql9/data/-llogfilestart或者:$./bin/postmaster-D/data/services/postgresql9/data>logfile2>&1&

2. 连接postgresSQL:

$./bin/psql

查看客户端字符编码:

查看服务端字符编码:


PostgreSQL的控制台命令:

\h:查看SQL命令解释。\?:查看psql命令列表。\isqlfile:调用后缀为sql的文件并输出。\l:列出所有数据库。\c[databasename]:连接其他数据库。\d:列出当前数据库的所有表.\d[tablename]:列出表结构。\d+[tablename]:查看表基本情况。\du:列出所有用户。\e:打开文本编辑器。\conninfo:列出当前数据库和连接的信息。