1.postgreSQL介绍:
PostgreSQL是一个功能强大的开源对象关系数据库系统,它使用并扩展了SQL语言,并结合了许多安全存储和扩展最复杂数据工作负载的功能。
2.postgreSQL特点:
免费,开源,高度可扩展性。数据完整性,并发性,可靠性,灾难恢复。安全。
3.postgreSQL安装:
系统环境 ; Ubuntu16.04 LTS
使用源码编译安装postgreSQL:
下载postgreSQL: # wget --no-cookies --no-check-certificate https://ftp.postgresql.org/pub/source/v9.5.14/postgresql-9.5.14.tar.gz 创建安装的目录: # mkdir /data/{services,packages,untar} -p 安装依赖包: # apt-get install -y libreadline6-dev libxslt-dev zlib1g-dev systemtap-sdt-dev libxml2-dev 解压软件包: # tar -zxvf postgresql-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 && make install //编译并安装 安装完成后的提示: PostgreSQL installation complete.设置postgresql共享库搜索路径:
方法1: 定义LD_LIBRARY_PATH的变量。 # export LD_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 "export PATH=$PATH:/data/services/postgresql9/bin" >> /etc/profile # source /etc/profile //立即生效。创建postgres账户并设置密码:
# useradd -d /data/services/postgresql9/ -M postgres # echo -e "123456\n123456" | passwd postgres 更改属主和属组: # chown -R postgres.postgres /data/services/postgresql9/创建数据目录和初始化数据目录:
# mkdir /data/services/postgresql9/data # su - postgres $ bin/initdb -D /data/services/postgresql9/data/
设置ubuntu16.04下系统的语言和编码设置:
# apt-get install -y language-pack-zh-hant language-pack-zh-hans language-selector-gnome # dpkg-reconfigure locales 选择zh_CN.UTF-8和en_US.UTF-8编码。 编码配置文件: /var/lib/locales/supported.d/ 该文件下有三个文件: en zh-hans zh-hant #dpkg-reconfigure --force locales 强制更新,使设置生效。
启动服务:
$ bin/pg_ctl -D /data/services/postgresql9/data/ -l logfile start 或者: $ ./bin/postmaster -D /data/services/postgresql9/data > logfile 2>&1 &2. 连接postgresSQL:
$ ./bin/psql查看客户端字符编码:
查看服务端字符编码:
PostgreSQL的控制台命令:
\h : 查看SQL命令解释。 \? : 查看psql命令列表。 \i sqlfile : 调用后缀为sql的文件并输出。 \l : 列出所有数据库。 \c [databasename] : 连接其他数据库。 \d : 列出当前数据库的所有表. \d [tablename] : 列出表结构。 \d+ [tablename] : 查看表基本情况。 \du : 列出所有用户。 \e : 打开文本编辑器。 \conninfo : 列出当前数据库和连接的信息。另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
文章标题:PostgreSQL安装和基本使用(一)-创新互联
路径分享:http://tyjierui.cn/article/dspdgo.html