首页 > 数据库 >PostgreSQL-错误处理集(持续更新... ...)

PostgreSQL-错误处理集(持续更新... ...)

时间:2023-08-04 14:35:34浏览次数:47  
标签:... PostgreSQL postgres drop pgccc table 错误处理 ljfz pg

1 无法删除用户

ERROR:角色不能被删除,因为有对象依赖于它

LINE 1:模式 public 的权限/用户下有表存在

解决方法:收回赋予此用户的 模式 public 的权限,并删除用户下的表,即可正常删除。

postgres=# \du
                                   List of roles
 Role name |                         Attributes                         | Member of 
-----------+------------------------------------------------------------+-----------
 ljfz      |                                                            | {}
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS | {}

postgres=# drop user ljfz;
ERROR:  role "ljfz" cannot be dropped because some objects depend on it
DETAIL:  privileges for schema public
owner of table ta
postgres=# 
postgres=# revoke usage on schema public from ljfz;
REVOKE
postgres=# drop user ljfz;
ERROR:  role "ljfz" cannot be dropped because some objects depend on it
DETAIL:  owner of table ta
postgres=# 
postgres=# \d
         List of relations
 Schema |  Name  | Type  |  Owner   
--------+--------+-------+----------
 public | mydata | table | postgres
 public | ta     | table | ljfz
(2 rows)

postgres=# drop table ta;
DROP TABLE
postgres=# drop user ljfz;
DROP ROLE
postgres=#

2 无法删除数据库

ERROR:其他用户正在访问数据库

LINE 1:还有一个使用数据库的会话

解决方法:KILL 会话相关的进程

[postgres@pgccc ~]$ psql
psql (15.2)
Type "help" for help.

postgres=# \l
                                                 List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    | ICU Locale | Locale Provider |   Access privileges   
-----------+----------+----------+-------------+-------------+------------+-----------------+-----------------------
 postgres  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | 
 subdb     | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | =Tc/postgres         +
           |          |          |             |             |            |                 | postgres=CTc/postgres+
           |          |          |             |             |            |                 | ljfz=c/postgres
 template0 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | =c/postgres          +
           |          |          |             |             |            |                 | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |            | libc            | =c/postgres          +
           |          |          |             |             |            |                 | postgres=CTc/postgres
(4 rows)

postgres=# drop database subdb;
ERROR:  database "subdb" is being accessed by other users
DETAIL:  There is 1 other session using the database.
postgres=# \q
[postgres@pgccc ~]$ ps -axjf |grep postgres
19326 26702 26702 19326 pts/0    13158 S        0   0:00  |       \_ su - postgres
19042 24317 24317 19042 pts/1      516 S        0   0:00          \_ su - postgres
24318   517   516 19042 pts/1      516 S+    1000   0:00                  \_ grep --color=auto postgres
    1 13926 13926 13926 ?           -1 Ss    1000   0:00 /pgccc/app/15.2/bin/postgres -D /pgccc/pgdata
13926 13927 13927 13927 ?           -1 Ss    1000   0:00  \_ postgres: checkpointer 
13926 13928 13928 13928 ?           -1 Ss    1000   0:00  \_ postgres: background writer 
13926 13930 13930 13930 ?           -1 Ss    1000   0:00  \_ postgres: walwriter 
13926 13931 13931 13931 ?           -1 Ss    1000   0:00  \_ postgres: autovacuum launcher 
13926 13932 13932 13932 ?           -1 Ss    1000   0:00  \_ postgres: logical replication launcher 
13926  2771  2771  2771 ?           -1 Ss    1000   0:00  \_ postgres: ljfz subdb [local] idle
[postgres@pgccc ~]$ kill -9 2771
[postgres@pgccc ~]$ psql
psql (15.2)
Type "help" for help.

postgres=# drop database subdb;
DROP DATABASE
postgres=#

3 无法创建表

ERROR:schema public 的权限被拒绝。即权限缺失。

LINE 1:创建表... ...

解决方法:授权用户在 schema public 上的权限 create ,即可。(提示不能 create table,当然是缺少权限 create )

[postgres@pgccc ~]$ psql
psql (15.2)
Type "help" for help.

postgres=# 
postgres=# create user ljfz;
CREATE ROLE
postgres=# \c postgres ljfz
You are now connected to database "postgres" as user "ljfz".
postgres=> create table ta (id int);
ERROR:  permission denied for schema public
LINE 1: create table ta (id int);
                     ^
postgres=> \c postgres postgres
You are now connected to database "postgres" as user "postgres".
postgres=# grant create on schema public to ljfz;
GRANT
postgres=# \c postgres ljfz
You are now connected to database "postgres" as user "ljfz".
postgres=> create table ta(id int);
CREATE TABLE
postgres=>

4 大版本升级提示严重错误

提示:新的安装中缺少可加载的插件。你可以将插件从旧的集簇删除,也可将其添加到新集簇。

解决方法:查看下方提示的日志记录,提示缺少 file_fdw 。这里的处理是,将其从 旧集簇 删除 

[postgres@pgccc ~]$ /pgccc/app/15.2/bin/pg_upgrade -b /pgccc/app/14.7/bin -B /pgccc/app/15.2/bin -d /pgccc/pgdata -D /pgccc/pgdata.new -c
Performing Consistency Checks
-----------------------------
Checking cluster versions                                   ok
Checking database user is the install user                  ok
Checking database connection settings                       ok
Checking for prepared transactions                          ok
Checking for system-defined composite types in user tables  ok
Checking for reg* data types in user tables                 ok
Checking for contrib/isn with bigint-passing mismatch       ok
Checking for presence of required libraries                 fatal

Your installation references loadable libraries that are missing from the
new installation.  You can add these libraries to the new installation,
or remove the functions using them from the old installation.  A list of
problem libraries is in the file:
    /pgccc/pgdata.new/pg_upgrade_output.d/20230801T100522.997/loadable_libraries.txt

Failure, exiting
[postgres@pgccc ~]$ cat /pgccc/pgdata.new/pg_upgrade_output.d/20230801T100522.997/loadable_libraries.txt
could not load library "$libdir/file_fdw": ERROR:  could not access file "$libdir/file_fdw": No such file or directory
In database: postgres
[postgres@pgccc ~]$ pg_start
waiting for server to start....2023-08-01 10:06:35.705 CST [28982] LOG:  redirecting log output to logging collector process
2023-08-01 10:06:35.705 CST [28982] HINT:  Future log output will appear in directory "log".
 done
server started
[postgres@pgccc ~]$ psql
psql (14.7)
Type "help" for help.

postgres=# drop extension file_fdw;
ERROR:  cannot drop extension file_fdw because other objects depend on it
DETAIL:  server pg_log depends on foreign-data wrapper file_fdw
user mapping for postgres on server pg_log depends on server pg_log
foreign table pglog3 depends on server pg_log
foreign table passwd depends on server pg_log
foreign table pglog4 depends on server pg_log
foreign table pglog5 depends on server pg_log
HINT:  Use DROP ... CASCADE to drop the dependent objects too.
postgres=#
postgres=# drop extension file_fdw CASCADE;
NOTICE:  drop cascades to 6 other objects
DETAIL:  drop cascades to server pg_log
drop cascades to user mapping for postgres on server pg_log
drop cascades to foreign table pglog3
drop cascades to foreign table passwd
drop cascades to foreign table pglog4
drop cascades to foreign table pglog5
DROP EXTENSION
postgres=#

标签:...,PostgreSQL,postgres,drop,pgccc,table,错误处理,ljfz,pg
From: https://blog.51cto.com/baoyw/6962060

相关文章

  • 俩人同样写代码,我拿七千他咋五万八...(送送送)
    ......
  • 深入探讨API调用性能优化与错误处理
    随着互联网技术的不断发展,API(应用程序接口)已经成为软件系统中重要的组成部分。而优化API调用的性能以及处理错误和异常情况则是保障系统稳定性和可靠性的关键。本文将从以下几个方面来探讨如何进行性能优化和错误处理。一、优化API调用的性能1.使用合适的数据传输格式选择合适的数......
  • 深入探讨API调用性能优化与错误处理
    ​随着互联网技术的不断发展,API(应用程序接口)已经成为软件系统中重要的组成部分。而优化API调用的性能以及处理错误和异常情况则是保障系统稳定性和可靠性的关键。本文将从以下几个方面来探讨如何进行性能优化和错误处理。一、优化API调用的性能1.使用合适的数据传输格式选择......
  • ES6箭头函数,{...object1, ...object2}使用解构赋值《...》提示错误的解决办法
    原因分析解构赋值大括号{}与原箭头函数的大括号冲突,导致无法正常解析解决办法错误示例()=>{...object1,...object2}正确示例()=>({...object1,...object2})//即将解构赋值的内容用括号括起来......
  • mysql插入报错java.sql.SQLException: Incorrect string value: '\xF0\x9F\x87\xA
    背景环境java8,centos7.9,mysql8.0.34新装的环境,默认给装了mysql8,想着与时俱进用下新版,结果插入就报错java.sql.SQLException:Incorrectstringvalue:'\xF0\x9F\x87\xA8\xF0\x9F...'forcolumn解决方法这个错误通常是由于MySQL数据库中的字符集不支持存储特定的字符或表情符......
  • 【js学习笔记二十二】...扩展运算符
     目录前言导语 代码部分 运行结果前言我是歌谣我有个兄弟巅峰的时候排名c站总榜19叫前端小歌谣曾经我花了三年的时间创作了他现在我要用五年的时间超越他今天又是接近兄弟的一天人生难免坎坷大不了从头再来歌谣的意志是永恒的放弃很容易但是坚持一定很酷导语歌谣歌谣......
  • postgresql 常用的删除重复数据方法
    一、最高效方法测试环境验证,6600万行大表,删除2200万重复数据仅需3分钟deletefromdeltestawherea.ctid=any(array(selectctidfrom(selectrow_number()over(partitionbyid),ctidfromdeltest)twheret.row_number>1)); --family_no相同的数据,保留i......
  • postgresql database basis
    postgresqlbasisthesystemcatalogtablesofpsotgresqlincludethefollowingtables:pg_databases:containsinformationabout alldatabases,suchasdatabasename,owner,characterset,etcpg_tablespace: containsinformationaboutalltablespaces,suc......
  • 当编译器没有SetProcessDpiAwareness()这个函数时...
    #include<Shlobj.h>intsetdpi(){//定义一个函数指针类型typedefHRESULT(WINAPI*SetProcessDpiAwarenessFunc)(intvalue);//加载Shcore.dllHMODULEhModule=LoadLibrary("Shcore.dll");if(hModule==NULL){//加载失败......
  • 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.......