473,903 Members | 4,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Temporary tables and miscellaneous schemas

Whenever I create a temporary table, with something like

CREATE TEMPORARY TABLE temptable1 AS SELECT * FROM paid.ad_hoc_que ry;

New schemas appear, with names like "pg_temp_1" . I guess the appearance
of these schemas with "temp" in the name indicates that they are
"temporary" schemas and related to the temporary table creation, but the
schemas persist even after the end of the session in which the temporary
table was created.

What's up with these miscellaneous schemas? Are they in fact related to
the creation of temporary tables? Should they disappear when the session
closes, as should the temporary table? If they continue persisting after
the session closes, how do I get rid of them?

~Berend Tober


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05
30 9869
> >> This will certainly not work, since you don't own your pg_temp_*
schema (the bootstrap UID does). I disagree with the goal anyway
...

OK, others liked the goal of showing only your local schema ---
what is your proposal?


My proposal is to do nothing ;-).

If you want to suppress *all* pg_temp_ schemas from the \dn listing,
that would be defensible maybe. I'd be inclined to say that
pg_toast should be hidden as well if that approach is taken, because
then you are basically saying that \dn is not the truth but only the
stuff we think you should be interested in. (This is why I don't
agree with it.)


Um, I forget whether or not this was given any credence or anyone
weighed in on it, but what about having two modes for psql? An admin
mode which hides nothing and is the default for superuser connections,
and a user mode which is the default for non-DBA connections. Then we
could pretty easily rationalize hiding various schemas as they may or
may not be relevant. In the case where a normal user would want their
\command to show admin tables, schemas, etc., they could \set
ADMIN_MODE or toggle it on/off with a \command like \P.

I've got the psql foo to pull this off pretty easily, but don't
recall a thumbsup/down on the idea. -sc

--
Sean Chittenden

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddres sHere" to ma*******@postg resql.org)

Nov 12 '05 #21
Tom Lane wrote:
Bruce Momjian <pg***@candle.p ha.pa.us> writes:
Tom Lane wrote:
This will certainly not work, since you don't own your pg_temp_* schema
(the bootstrap UID does). I disagree with the goal anyway ...

OK, others liked the goal of showing only your local schema --- what is
your proposal?


My proposal is to do nothing ;-).

If you want to suppress *all* pg_temp_ schemas from the \dn listing,
that would be defensible maybe. I'd be inclined to say that pg_toast
should be hidden as well if that approach is taken, because then you are
basically saying that \dn is not the truth but only the stuff we think
you should be interested in. (This is why I don't agree with it.)


The main problem is that someone with 1k connection is seeing 1k
pg_temp_* schemas lists, which certainly isn't good.

Maybe we could do a UNION and add a "pg_temp_*" line to stand for all
pg_temp_ schemas. Another idea would be to print a message at the
bottom saying other temp schemas were supressed. By showing the temp
schema name, you can see all your temp tables:

test=> create temp table x(y int);
CREATE TABLE
test=> \dn
List of schemas
Name | Owner
--------------------+----------
information_sch ema | postgres
pg_catalog | postgres
pg_temp_1 | postgres
pg_temp_2 | postgres
pg_toast | postgres
public | postgres
(6 rows)

test=> \d pg_temp_1.*
Table "pg_temp_1. x"
Column | Type | Modifiers
--------+---------+-----------
y | integer |

This seems like a good reason for the patch so people can see their own
schemas --- I don't think people are using \dn as an authorative result
--- they can always select from pg_namespace.

--
Bruce Momjian | http://candle.pha.pa.us
pg***@candle.ph a.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #22
Sean Chittenden wrote:

If you want to suppress *all* pg_temp_ schemas from the \dn listing,
that would be defensible maybe. I'd be inclined to say that
pg_toast should be hidden as well if that approach is taken, because
then you are basically saying that \dn is not the truth but only the
stuff we think you should be interested in. (This is why I don't
agree with it.)


Um, I forget whether or not this was given any credence or anyone
weighed in on it, but what about having two modes for psql? An admin
mode which hides nothing and is the default for superuser connections,
and a user mode which is the default for non-DBA connections. Then we
could pretty easily rationalize hiding various schemas as they may or
may not be relevant. In the case where a normal user would want their
\command to show admin tables, schemas, etc., they could \set
ADMIN_MODE or toggle it on/off with a \command like \P.

I've got the psql foo to pull this off pretty easily, but don't
recall a thumbsup/down on the idea. -sc


I would like to see a big reason before making psql behave differently
for different people/modes.

--
Bruce Momjian | http://candle.pha.pa.us
pg***@candle.ph a.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #23
Sean Chittenden <se**@chittende n.org> writes:
Um, I forget whether or not this was given any credence or anyone
weighed in on it, but what about having two modes for psql? An admin
mode which hides nothing and is the default for superuser connections,
and a user mode which is the default for non-DBA connections.


I thought that would be likely to create more confusion than it solves.

To take just one problem, the newbies who could use the "friendly user"
mode are very likely the same ones who do all their work as postgres,
because it hasn't occurred to them to create any unprivileged users.
They won't get the benefit of it if we make it act as you suggest.
BTW, if I lose this argument, there *is* a workable way to get the
behavior Bruce wants: use current_schemas () to detect which temp schema
is in your search path.

regression=# select nspname from pg_namespace;
nspname
--------------------
pg_temp_2
pg_toast
pg_temp_1
pg_catalog
public
information_sch ema
(6 rows)

regression=# select nspname from pg_namespace where nspname not like
regression-# 'pg\\_temp\\_%' or nspname = any (current_schema s(true));
nspname
--------------------
pg_toast
pg_catalog
public
information_sch ema
(4 rows)

regression=# create temp table foo(f1 int);
CREATE TABLE
regression=# select nspname from pg_namespace where nspname not like
regression-# 'pg\\_temp\\_%' or nspname = any (current_schema s(true));
nspname
--------------------
pg_temp_2
pg_toast
pg_catalog
public
information_sch ema
(5 rows)
regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #24

Oh, that's not fair --- you gave us the solution to something you don't
agree with. ;-)

Anyway, I agree a separate admin mode can cause more confusion that it
solves.

I see a few goals here:

Prevent \dn from showing lots of lines for large installs
Show the local temp schema so people can query it

Is there a solution that doesn't supress all the schemas but the local
one?

How about if we add a UNION that does:

UNION
SELECT 'non-local temp schemas skipped', NULL

That would document that we are skipping them, and even give them an
entry in the output:

List of schemas
Name | Owner
--------------------+----------
information_sch ema | postgres
pg_catalog | postgres
pg_temp_2 | postgres
pg_toast | postgres
public | postgres
{other pg_temp_*} | postgres
(7 rows)
---------------------------------------------------------------------------

Tom Lane wrote:
Sean Chittenden <se**@chittende n.org> writes:
Um, I forget whether or not this was given any credence or anyone
weighed in on it, but what about having two modes for psql? An admin
mode which hides nothing and is the default for superuser connections,
and a user mode which is the default for non-DBA connections.


I thought that would be likely to create more confusion than it solves.

To take just one problem, the newbies who could use the "friendly user"
mode are very likely the same ones who do all their work as postgres,
because it hasn't occurred to them to create any unprivileged users.
They won't get the benefit of it if we make it act as you suggest.
BTW, if I lose this argument, there *is* a workable way to get the
behavior Bruce wants: use current_schemas () to detect which temp schema
is in your search path.

regression=# select nspname from pg_namespace;
nspname
--------------------
pg_temp_2
pg_toast
pg_temp_1
pg_catalog
public
information_sch ema
(6 rows)

regression=# select nspname from pg_namespace where nspname not like
regression-# 'pg\\_temp\\_%' or nspname = any (current_schema s(true));
nspname
--------------------
pg_toast
pg_catalog
public
information_sch ema
(4 rows)

regression=# create temp table foo(f1 int);
CREATE TABLE
regression=# select nspname from pg_namespace where nspname not like
regression-# 'pg\\_temp\\_%' or nspname = any (current_schema s(true));
nspname
--------------------
pg_temp_2
pg_toast
pg_catalog
public
information_sch ema
(5 rows)
regards, tom lane


--
Bruce Momjian | http://candle.pha.pa.us
pg***@candle.ph a.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #25
Bruce Momjian <pg***@candle.p ha.pa.us> writes:
How about if we add a UNION that does:
UNION
SELECT 'non-local temp schemas skipped', NULL
I think showing that would only be appropriate if we actually *did* skip
some. Finding that out would complicate the query unduly IMHO.
I see a few goals here:
Prevent \dn from showing lots of lines for large installs
Show the local temp schema so people can query it


If those are agreed to be the goals then we end up with your original
solution (or a working implementation of same anyway).

I'd like to see some input from other people about what they want...

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postg resql.org

Nov 12 '05 #26
> > Um, I forget whether or not this was given any credence or anyone
weighed in on it, but what about having two modes for psql? An
admin mode which hides nothing and is the default for superuser
connections, and a user mode which is the default for non-DBA
connections.


I thought that would be likely to create more confusion than it
solves.

To take just one problem, the newbies who could use the "friendly
user" mode are very likely the same ones who do all their work as
postgres, because it hasn't occurred to them to create any
unprivileged users. They won't get the benefit of it if we make it
act as you suggest.


Hrm, well, two flaws with that argument being:

1) Users who (ab)use DBA accounts aren't likely the ones with
gazillions of pg_temp_* tables and probably don't even make use of
temp tables or care about pg_toast. No harm, no foul, as the
feature isn't likely used.

2) Queries that are written by a DBA and given to a user will still
work when executed by the user, so the confusion is limited to a
\command not showing the same results that a DBA sees.

Seeing extra info if your prompt is '#' and not '%' shouldn't surprise
anyone. Few complain about tab completion in shells not listing
programs that aren't readable by the current user.

eg:

% /usr/local/bin/root_only_cmd[TAB]
*system beeps, root_only_cmd_h ere isn't executable by $USER*
# /usr/local/bin/root_only_cmd[TAB]
# /usr/local/bin/root_only_cmd_h ere
-sc

--
Sean Chittenden

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #27
I have a challenge to be able to grant all to the database, and then
have subsequent tables accessible by all users.

It seems to me that this is how a database should work. I do realize
that postgres doesn't do this now. Is there a way around this? Using
rules or some other mechanism?

Dave
--
Dave Cramer <da**@fastcrypt .com>
fastcrypt
--
Dave Cramer <Da**@micro-automation.net>
---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #28
Sean Chittenden <se**@chittende n.org> writes:
To take just one problem, the newbies who could use the "friendly
user" mode are very likely the same ones who do all their work as
postgres, because it hasn't occurred to them to create any
unprivileged users. They won't get the benefit of it if we make it
act as you suggest.
Hrm, well, two flaws with that argument being: 1) Users who (ab)use DBA accounts aren't likely the ones with
gazillions of pg_temp_* tables and probably don't even make use of
temp tables or care about pg_toast. No harm, no foul, as the
feature isn't likely used.


Perhaps, but you were arguing (I thought) for instituting a bunch of
differences in behavior between user and DBA modes, not only this one.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postg resql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #29
On Mon, Oct 27, 2003 at 16:58:50 -0500,
Dave Cramer <da**@fastcrypt .com> wrote:
I have a challenge to be able to grant all to the database, and then
have subsequent tables accessible by all users.
Granting access to a database does specifically what the documentation
says it does, which does affect the default access rights for newly
created objects.
It seems to me that this is how a database should work. I do realize
that postgres doesn't do this now. Is there a way around this? Using
rules or some other mechanism?


Currently there really isn't a way to do this. You could run a cron script
that sets protections for tables on a regular schedule.

What it seems you really want is a per user or per database value that
specifies a default access mode for newly created objects roughly
similar to umask on Unix systems.

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2096
by: Soefara | last post by:
Dear Sirs, I have been developing an application on Windows with MySQL 3.23, making use of temporary tables. Now when I try to port the application to a Unix box running also MySQL 3.23, I keep running into "access denied" errors with the queries which employ temporary tables. This only happens with CREATE TEMPORARY TABLE type queries, all other queries work fine.
11
16306
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the equivalent to the SQL 'with' using TSQL? If there is not one, what is the TSQL solution to creating a temporary table that is associated with an SQL statement? Examples would be appreciated. Thank you!!
1
2615
by: Sampath Reddy | last post by:
Hi Everybody, We are using UDB v8.1 I will explain about my Stored procedures which we are executing in UDB AIX box. We have 3 millions(apporox) of data in 22 tables. By applying the business logic through Stored procedures on 22 tables and writing into 3 new tables. We have used all temporary tables except starting 22 tables. The Stored procedures we have used nearly 6 temporary tables to handle the business logic. Finally we are loading...
2
6984
by: Keith Watson | last post by:
Hi, we are currently implementing an application running on DB2 V7 on Z/OS using largely COBOL stored procedures, managed using WLM. Some of these stored procedures declared global temporary tables, which are declared with ON COMMIT DELETE ROWS to perform work on and then return these temporary tables to the client (which is a message driven EJB connecting via DB2 connect). The client reads the data in the result sets, creates some XML...
3
3282
by: Mike Ridley | last post by:
I have 2 databases called (for example) "progs.mdb" and "files.mdb". Both these databases reside on computer "myserver". The progs database has links to the tables in the files database. "myclient1" runs a shortcut "msaccess.exe \\myserver\progs.mdb /x startmacro". "myclient2" runs his shortcut "msaccess.exe \\myserver\progs.mdb /x startmacro". If I use a temporary table I take it that it will be created on "myserver" in the...
5
1831
by: m.e.bruche | last post by:
Hi, In my database, I created a lot of tables before I found out about schemas. It's a mess! Suppose I want to get organised, and create a couple of schemas. How do I move existing tables into my newly created schemas? e.g.
1
27056
by: Stefan van Roosmalen | last post by:
Hi there, Is there a way to list the TEMPORATY tables? I have tried SHOW TABLES, but this command only list the regular tables. Thank you very much for your answer. Regards, Stefan.
12
7043
by: nyathancha | last post by:
Hi, I have a question regarding best practices in database design. In a relational database, is it wise/necessary to sometimes create tables that are not related to other tables through a foreign Key relationship or does this always indicate some sort of underlying design flaw. Something that requires a re evaluation of the problem domain? The reason I ask is because in our application, the user can perform x
5
8851
by: Rahul B | last post by:
Hi, I have very little knowledge about creating Procedures/functions in DB2. When i tried to create the test function like CREATE FUNCTION GET_TEST (P_TEST_ID INTEGER, P_SEL_OR_SORT INTEGER,
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11279
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10872
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10981
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
8047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4307
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3323
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.