pgsql常用命令总结

pgsql常用命令及相关总结

命令

命令登录

psql -U postgres -h 127.0.0.1 -p 5432 -d vism

查看所有数据库:\l
进入某一数据库:\c 数据库名字
查看数据库表:\dt
列出某一张表格的结构:\d 表名
查看某个表的所有数据:select * from 表名;(后面别忘分号)
导出数据库:/usr/pgsql-12/bin/pg_dump -U 用户名 数据库名 > /home/username/db.sql
导入数据库:psql -U 用户名 数据库名(缺省时同用户名) < /home/username/db.sql
退出数据库:ctrl + z 或者 \q
查询public模式下所有表名:
select tablename from pg_tables where schemaname=‘public’

linux命令导出指定表

pg_dump -U postgres -t public.test -f test.sql vism
psql -U postgres -d vism -f test.sql
pg_dump -U username -d dbname -t table_name -a -f table_name.sql

其中,-t 参数指定要导出的表名,-a 参数指定只导出数据而不导出表结构,-f 参数指定导出数据的文件名。

备份库
pg_dump -U ‘username’ -p ‘port number’ -d ‘databse’ > ‘dump file name’
pg_dump -U postgres -p 5432 -d vism >vism.dump

参考:
https://blog.csdn.net/lhpbird/article/details/126125016

SpringBoot连接PostgreSQL的配置

引入依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>42.3.3</version>
    <scope>runtime</scope>
</dependency>

连接配置(指定模式)

spring:
  datasource:
    driver-class-name: org.postgresql.Driver
    url: jdbc:postgresql://localhost:5432/database?currentSchema=schema
    username: xxx
    password: xxx

猜你喜欢

转载自blog.csdn.net/weixin_42949219/article/details/132718166