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.Driverurl: jdbc:postgresql://localhost:5432/database?currentSchema=schemausername: xxxpassword: xxx