>If this happens, all my database connections get this error when trying
>to access the database and I need to restart postgresql. The problem
>causing this error needs to be something like this:
>
> create table table2 (col1 text);
> insert into table2 (col1) values ('some data');
> begin work;
> drop table table1;
> alter table table2 rename to table1;
> commit;
What happens if two different connections try to "drop table table1"? Try
doing it step by step in two different connections?
I did a vaguely similar thing.
I did a BEGIN, DROP TABLE, ROLLBACK. And yes I know you're not supposed to
be able to rollback a drop table, but I could not recreate the table- I had
to do a manual file system delete of the table. If a connection gets broken
during a transaction, and you get a rollback, you could encounter the same
problem.
I did what I did coz I was curious. But creating/Dropping tables in a
transaction does not appear to be a "good thing", and that's not just for
PostgreSQL. I believe doing data definition stuff in transactions is not
recommended.
Is it possible to achieve your goals by using things like
"delete * from table1 where id!=stuffIwant" instead of dropping it?
Cheerio,
Link.