renaming index leaves database inconsistent

Started by Richard Pooleover 26 years ago2 messagesbugs
Jump to latest
#1Richard Poole
rp@gxn.net

Your name : Richard Poole
Your email address : rp@gxn.net

System Configuration
---------------------
Architecture (example: Intel Pentium) : Intel Pentium

Operating System (example: Linux 2.0.26 ELF) : Linux 2.2.5 ELF

PostgreSQL version (example: PostgreSQL-6.5.3): PostgreSQL-6.5.3

Compiler used (example: gcc 2.8.0) : egcs 1.1.2

Please enter a FULL description of your problem:
------------------------------------------------

If I try to do ALTER TABLE ... RENAME on an index, it fails and does not
change the system catalogues, but does rename the file containing the
index. Any operation which would access the index then fails.

I know I shouldn't do that but if I try it should fail gracefully; as it
is this seems to need hand-repairing.

Please describe a way to repeat the problem. Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------

rptest=> create table foo(i int);
CREATE
rptest=> create index foo_index on foo(i);
CREATE
rptest=> alter table foo_index rename to new_foo_index;
ERROR: TypeRename: type foo_index not defined
rptest=> insert into foo values (42);
ERROR: mdopen: couldn't open foo_index: No such file or directory
rptest=> \q
[rp@judy rp]$ su postgres
Password:
[postgres@judy rp]$ ls /var/pgsql/base/rptest/ | grep foo
foo
new_foo_index

If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

I don't know the code at all, but it seems there should be a check at the
top of renamerel() (in src/backend/commands/rename.c) that the relation
you're renaming isn't an index, before you do the rename of the file.
Alternatively it would be nice if you *could* rename indices, but I don't
know what other repercussions that might have.

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Richard Poole (#1)
Re: [BUGS] renaming index leaves database inconsistent

Richard Poole <rp@gxn.net> writes:

rptest=> create table foo(i int);
rptest=> create index foo_index on foo(i);
rptest=> alter table foo_index rename to new_foo_index;
ERROR: TypeRename: type foo_index not defined

In current sources I get
ERROR: foo_index is an index relation
and no damage has been done. Seems like it ought to be possible to
rename an index, however, so I'd say this is a stopgap not a solution.

regards, tom lane