@zhangyy
2021-11-16T03:20:50.000000Z
字数 5320
阅读 342
PostgreSQL系列







postgreSQL 12 版本特性


























create user flyfish with password '123.com' nocreatedb;create database flyfishdb with owner=flyfish;

psql.exe -h 192.168.100.90 -p 5432 -U flyfish -d flyfishdbcreate table flyfishtable(name varchar(50));insert into flyfishtable values('haha');commit ;select * from flyfishtable




windows server 2019x64 准备下载 postgresqlhttps://www.enterprisedb.com/download-postgresql-binaries















环境准备:echo "export LANG=en_US.UTF8" >> ~/.bash_profilecat ~/.bash_profilesource ~/.bash_profilemount /dev/cdrom /mntcd /etc/yum.repos.dmkdir bkmv *.repo bk/echo "[EL7]" >> itpux.repoecho "name = linux 7.6 dvd" >> itpux.repoecho "baseurl=file://mnt" >> itpux.repoecho "gpgcheck=0" >> itpux.repoecho "enabled=1" >> itpux.repoyum listsystemctl set-default multi-user.targetsystemctl get-defaultecho "vm.swappiness=10" >> /etc/sysctl.confecho "fs.aio-max-nr = 1048576" >> /etc/sysctl.confecho "fs.file-max = 6815744" >> /etc/sysctl.confecho "net.ipv4.ip_local_port_range = 9000 65500" >> /etc/sysctl.confecho "net.core.rmem_default = 262144" >> /etc/sysctl.confecho "net.core.rmem_max = 4194304" >> /etc/sysctl.confecho "net.core.wmem_default = 262144" >> /etc/sysctl.confecho "net.core.wmem_max = 1048586" >> /etc/sysctl.confecho "kernel.shmmax = 1288490188" >> /etc/sysctl.confecho "kernel.shmall = 314572" >> /etc/sysctl.confecho "kernel.shmmni = 4096" >> /etc/sysctl.confecho "kernel.sem = 4096 2147483647 2147483646 512000" >> /etc/sysctl.confsysctl -pecho "* - nproc unlimited" > /etc/security/limits.d/90-nproc.confecho "SELINUX=disable" >/etc/selinux/configecho "#SELINUXTYPE=trageted" >> /etc/selinux/configcat /etc/selinux/configsetenforce 0systemctl status firewalld.servicesystemctl stop firewalld.servicesystemctl disable firewalld.serviceecho "session required pam_limits.so" >> /etc/pam.d/logincat /etc/pam.d/loginecho "* soft nproc unlimited" >>/etc/security/limits.confecho "* hard nproc unlimited" >>/etc/security/limits.confecho "* soft nofile 16384" >>/etc/security/limits.confecho "* hard nofile 65536" >>/etc/security/limits.confecho "* soft stack unlimited" >> /etc/security/limits.confecho "* hard stack unlimited" >>/etc/security/limits.confcat /etc/security/limits.confrm -f /etc/security/limits.d/*20**/vi /etc/default/grubGRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet numa=offtransparent_hugepage=never"grub2-mkconfig -o /etc/grub2.cfgnumastatnumactl --shownumactl --hardwareshutdown -r nowrm -f /etc/udev/rules.d/70-persistent-net.ruleshostname itpuxpg61echo "itpuxpg61" > /etc/hostnamevi /etc/sysconfig/network-scripts/ifcfg-ens33改 IP、删 UUIDreboot
安装postgreSQL安装依赖包yum install -y cmake make gcc zlib gcc-c++ perl readline readline-devel zlib zlib-devel perl python36 tcl openssl ncurses-devel openldap pam

创建 PostgreSQL 用户groupadd -g 60000 pgsqluseradd -u 60000 -g pgsql pgsqlecho "pgsql" |passwd --stdin pgsql创建安装目录mkdir -p /postgresql/{pgdata,archive,scripts,backup,pg12,soft}chown -R pgsql:pgsql /postgresqlchmod -R 775 /postgresql
编译postgresqlcd /postgresql/softtar -zxvf postgresql-12.2.tar.gzcd postgresql-12.2./configure --prefix=/postgresql/pg12 --without-readline (表示不显示历史)makemake install
su - pgsqlvim /root/.bash_profile---export LANG=en_US.UTF8export PS1="[`whoami`@`hostname`:"'$PWD]$'export PGPORT=5432export PGDATA=/postgresql/pgdataexport PGHOME=/postgresql/pgl2exportLD_LIBRARY_PATH=$PGHOME/lib:/lib64:/usr/lib64:/usr/local/lib64:/lib:/usr/lib:/usr/local/lib:$LD_LIBRARY_PATHexport PATH=$PGHOME/bin:$PATH:.export DATE=`date +"%Y%m%d%H%M"`export MANPATH=$PGHOME/share/man:$MANPATHexport PGHOST=$PGDATAexport PGUSER=postgresexport PGDATABASE=postgres---source /etc/profile
初始化su - pgsql/postgresql/pg12/bin/initdb -D /postgresql/pgdata -E UTF8 --locale=en_US.utf8 -U postgres可有这个命令启动:/postgresql/pg12/bin/pg_ctl -D /postgresql/pgdata -l logfile start


cd /postgresql/pgdata/vim postgresql.conf----listen_addresses = '*'port = 5432max_connections = 500logging_collector = onlog_directory = 'pg_log'log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log'log_truncate_on_rotation = onshared_buffers = 1024MBmax_wal_size = 1GBmin_wal_size = 80MB----vim pg_hba.conf---host all all 0.0.0.0/0 md5----
cd /postgresql/pg12/bin/./pg_ctl start 启动./pg_ctl stop 停止/postgresql/pg12/bin/pg_ctl -D /postgresql/pgdata -l logfile start 启动/postgresql/pg12/bin/pg_ctl -D /postgresql/pgdata -l logfile stop 停止---vi /etc/systemd/system/postgresql.service[Unit]Description=PostgreSQL database serverDocumentation=man:postgres(1)[Service]Type=notifyUser=pgsqlExecStart= /postgresql/pg12/bin/postgres -D /postgresql/pgdataExecReload=/bin/kill -HUP $MAINPIDKillMode=mixedKillSignal=SIGINTTimeoutSec=0[Install]WantedBy=multi-user.target----chmod +x /etc/systemd/system/postgresql.serviceservice postgresql start数据库 一般不 做 开机启动

连接数据psql -h127.0.0.1 -p5432

设置密码:\password postgres (设置密码:123.com)或者:alter user postgres with password '123.com';

psql -h192.168.100.11 -U postgres -p5432

create user flyfish with password '123.com' nocreatedb;create database flyfishdb with owner=flyfish;

psql -h 192.168.100.11 -p 5432 -U flyfish -d flyfishdbcreate table flyfishtable(name varchar(50));insert into flyfishtable values('haha');commit ;select * from flyfishtable;


\c flyfishdb flyfish 切换 数据库\dt + 查看 数据库下面的表\dt flyfishtable 查看 表的 信息\d flyfishtable 查看表结构

