____________________ | PG | MySQL | Oracle |
---|---|---|---|
查看所有表 | \dt
| show tables; | select * from dba_tables; |
查看表结构 | \d t1 \d+ t1 | desc t1 | desc t1 |
查看表上的索引 | select * from pg_indexes | SELECT * FROM mysql.`innodb_index_stats` a WHERE a.`database_name` = '数据库名' and a.table_name like '%表名%'; | SELECT * FROM dba_indexes |
连接数据库 | psql -h host -d database -U user -W | mysql -u root -pxxx | sqlplus user/pwd@tns |
切换数据库 | \c dbname username ; | use database ; | alter session set container=PDB1 ; |
显示可用数据库 | \l select * from pg_database; | show databases; | show pdbs ; |
查看表大小 | select pg_relation_size('t1'); select pg_size_pretty(pg_relation_size('t1')); SELECT pg_size_pretty(pg_total_relation_size('t1')); | SELECT TABLE_NAME AS `Table`, ROUND(((DATA_LENGTH + INDEX_LENGTH)/1024/1024),2) AS `Size(MB)` FROM information_schema.TABLES WHERE TABLE_NAME = 't1' | select bytes from user_segments where segment_name = 'T1' ; |
查看索引大小 | SELECT | select bytes from user_segments
| |
查看所有表空间 | select oid , * from pg_tablespace ; | select * from dba_tablespaces; select * from v$tablespace ; | |
查看表空间大小 | SELECT | select bytes from user_segments
| |
切换日志 | select pg_switch_wal() ; | flush logs; | alter system switch logfile ; |
查看数据库参数 | show work_mem; | Show variables like ‘%%’; | Show parameter xxx ; |
查看数据目录 | SHOW data_directory; | show variables like ‘%data%’ | select * from dba_data_files; |
日期转换及计算 | date_format(date,'%Y-%m-%d') | to_char() to_date() | |
根据查询创建表 | create table as select * from xxx ; | ||
开启时间计时 | \timing | ||
查看session | select * from pg_stat_activity ; | select * from information_schema.processlist | select * from v$session; |