Postgres tablespace size and reduction - postgresql

I've been trying postgres with a program that fetches data and puts it into the DB.
Right now the tablespace has filled the available space.
How can I cleanup the db in order to reduce it.
If I delete records, will the disk space be released?
Since I'd want to keep this under control, how can I say to postgres tablespace not to autoextend but to have a specific maximum sze?
Thanks

Related

Limit size of temporary tables (PostgreSQL)

I'm managing a PostgreSQL database server for some users who need to create temporary tables. One user accidentally sent a query with ridiculously many outer joins, and that completely filled the disk up.
PostgreSQL has a temp_file_limit parameter but it seems to me that it is not relevant:
It should be noted that disk space used for explicit temporary tables, as opposed to temporary files used behind-the-scenes in query execution, does not count against this limit.
Is there a way then to put a limit on the size on disk of "explicit" temporary tables? Or limit the row count? What's the best approach to prevent this?
The only way to limit a table's size in PostgreSQL is to put it in a tablespace on a file system of an appropriate size.
Since temporary tables are created in the default tablespace of the database you are connected to, you have to place your database in that size restricted tablespace. To keep your regular tables from being limited in the same way, you'd have to explicitly create them in a different, less limited tablespace. Make sure that your user has no permissions on that less limited tablespace.
This is a rather unappealing solution, so maybe you should rethink your requirement. After all, the user could just as well fill up the disk by inserting the data into a permanent table.

How to dis-connect and then re-connect a postgres tablespace?

Is it possible to dis-connect and re-connect a POSTGRES tablespace and all the associated objects within that tablespace?
I have a Postgres database with two tablespaces, one on a high-speed SSD drive (I've named this FASTSPACE) , and the other on a slower, traditional magnetic HDD (named SLOWSPACE). The slower tablespace is reserved for large volumes of historic data which is rarely accessed.
Is it possible to temporarily disconnect SLOWSPACE, with the intention of reconnecting it at a later date? the DROP TABLESPACE documentation can only be used once all database objects within it have been dropped.
I'm aware that I can backup all the tables in SLOWSPACE, then delete them, and then DROP the tablespace, however this will take time (there are several Terabytes of data). If I then need the archived data again I'll have create a new version of the SLOWSPACE tablespace from blank, then re-create all the objects from the backups. Again, this will take time.
Is there any way of temporarily disconnecting SLOWSPACE from the database - whilst still leaving the rest of the database up and running?
Update - happy to accept Franks Heikens two letter answer - 'no'

Postgres and Tablespace and indexes

I want to ask if its possible that a situation where the main table is in a different tablespace from the index if it affects performance.
i have a senario where a large table 250GB is in a tablespace and the indexes (3) with an average size of 40GB is in default tablespace. could this be the reason why queries are slow
No, unless one of these tablespaces is on slow storage.

Monitoring Db2 tablespace with partitioned table

How to monitor allocation data in tablespaces with partitioned table?
I want to know when my tablespaces will fill up before creating new tablespaces with new partition.
When I perform command:
db2pd -db DBTEST -tablespace
I got information with tablespace Statistics: UsablePgs and FreePgs.
The values remain the same even when I perform runstat on my table.
I thought that after runstat this value will grow.
The information returned by this call doesn't depend on runstats.
Think about this allocation info as "always current".
Consider using MON_GET_TABLESPACE
https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.sql.rtn.doc/doc/r0053943.html

How to set the table space of a sub select in PostgreSQL

I have a rather large Insert Query, and upon running this my slow disks fill up towards 100% upon where I revive:
Transaction aborted because DBD::Pg::db do failed: ERROR: could not write to hash-join temporary file: No space left on device
Sounds believable, I have a Fast drive with lots of space on it that i could use instead of the slow disk but I dont want to make the fast disk the default table-space or move the table im inserting into to the fast disk, I just want that data-blob that is generated as part of the insert query to be on the fast disk table-space. Is this possible is PostgreSQL and if so how?
version 9.1
You want the temp_tablespaces configuration directive. See the docs.
Temporary files for purposes such as sorting large data sets are also
created in these tablespaces
You must CREATE TABLESPACE the tablespace(s) before using them in an interactive SET temp_tablespaces command.
SET LOCAL temp_tablespaces may be used to set it only for the current transaction.