当前位置:首页 > 数据库 > 正文内容

postgresql 的安装使用

root4年前 (2021-06-08)数据库963
  1. 安装

    centos系统 9.6版本

    # Install the repository RPM

    sudo yum install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg- redhat-repo-latest.noarch.rpm

    # Install PostgreSQL:

    sudo yum install -y postgresql96-server

    sudo /usr/pgsql-9.6/bin/postgresql96-setup initd

    sudo systemctl enable postgresql-9.6

    sudo systemctl start postgresql-9.6


  2. 进入数据库

    su postgres

    psql

    \l

    #查看数据库列表 类似mysqlshow databases 

    \c [databasesname] 

    进入databasesname数据库,类似mysql的 use [databasesname] 

    \d

    查看当前数据的数据表,类似mysql show tables

  3. 创建数据库、表


    create database test; 

    # 创建数据库几乎跟mysql 一样 

            

    CREATE TABLE geoip_online_vps_to_landmark_rtt ( id INT PRIMARY KEY NOT NULL, numip BIGINT DEFAULT NULL, vp_rtt VARCHAR ) 

    # 创建数据表,差异主要体现在数据类型的不同,postgresql的数据类型还是比较丰富的。 注意在转换语句时对上合适的数据类型zz

            

    执行的查询sql 语句也近似一样,发现分页查询不一样。

    SELECT FROM geoip_online_landmark order by id limit 100000 OFFSET 0

    SELECT FROM geoip_online_landmark order by id limit ,100000;

    上面是postgresql的语句

            

    PostgreSQL在安装,使用,执行sql语句 跟MySQL 很相似。

    PG的主备复制属于物理复制,相对于MySQL基于binlog的逻辑复制

    PG主表采用堆表存放,MySQL采用索引组织表,PG能够支持更大的数据量,MySQL非常适合基于主键 匹配的查询、删改操作


  4. 修改配置允许远程

    vim   /var/lib/pgsql/9.6/data/postgresql.conf

    修改配置:#listen_addresses='localhost’修改为listen_addresses = '*' 

    vim   /var/lib/pgsql/9.6/data/pg_hba.conf

    在Ipv4项项目添加


    host    all             all             0.0.0.0/0            md5

        重启:systemctl restart postgresql-9.6

        远程登录

        psql -U postgres -h 192.168.1.228

       

        以下命令可以直接在命令行中直接填入密码 

   PGPASSWORD=pass1234 psql -U MyUsername myDatabaseName

    

常用命令

https://blog.csdn.net/weixin_34248118/article/details/92073646


扫描二维码推送至手机访问。

版权声明:本文由一叶知秋发布,如需转载请注明出处。

本文链接:https://zhiqiu.top/?id=115

分享给朋友:

相关文章

mysql 导出csv格式数据

mysql -e "select * from newsdb.t_hk_stock_news where id <100  ...

dataX:超强的数据库数据互导工具

安装下载安装包http://datax-opensource.oss-cn-hangzhou.aliyuncs.com/datax.tar.gz 然后解压进入解压后文件的./bin自检命令python  datax.py ../j...

centos7 安装mysql

centos7 安装mysql

下载rpm包wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm 安裝包仓库yum -y install * 或者yum -...

postgresql修改数据存储位置

postgresql修改数据存储位置

最近公司提供了一台新的服务器,同时有一个盘是ssd。同时为了测试postgresql的性能,将数据放置到ssd上系统centos7.9 数据库postgresql-9.6首先停掉数据库systemctl stop pos...

被Navicat坑哭的日常,版本问题

mysql5.7DROP TABLE IF EXISTS `xxx_copy1`;CREATE TABLE `xxx_copy1`  (  `id` int(11) UNSIGNED NOT NULL AUTO_INCR...

清空postgresql的缓存

系统:centos,版本:postgresql-9.6因为要测试postgresql的性能,当多次查询的时候查询结果会因为缓存用时很短,不能模拟出现实使用的场景。因此需要清除缓存。首先stop掉postgresqlsystemctl sto...