To verify if your user has the privilege to create temporary segments in a postgreSQL database, use this check:
psql -h localhost -d mydb -U myuser
SELECT has_database_privilege(current_user, current_database(), 'TEMP');
If the value returned shows:
has_database_privilege
------------------------
f
To be able to create a temporary table in this database, my user needs privileges to do so:
psql
postgres=# grant temp on database mydb to myser;
GRANT
The same test will now yield true instead of false:
SELECT has_database_privilege(current_user, current_database(), 'TEMP');
has_database_privilege
------------------------
t
(1 row)
I can now create a temporary table:
CREATE TEMP TABLE table_counts (table_name text, row_count bigint);
Before the grant, the access privileges for my database was
mydb=> \l+ mydb
| Access privileges |
+------------------------------+
| postgres=CTc/postgres +|
| myuser=c/postgres +|
After the grant:
| Access privileges |
+------------------------------+
| postgres=CTc/postgres +|
| myuser=Tc/postgres +|
Notice how the privileges for "myuser" has a "T" ammended to it. This indicate the permission to create temporary objects.