DB2 tablespace space issue - db2

I have created db2 db with default space 4k,now my application is throwing space issue
SQLCODE: -1585, SQLSTATE: 54048, SQLERRMC: null
no sufficient space allocated for temp tablespace
how to overcome this
can any one help on this.

DB2 has different type of tablespaces
Regular (data, your default TableSpace)
Large (data with long rows)
Catalog (metadata)
User temporary (for temporary tables)
System temporary (for internal operations like sorts, joins, etc that sometimes overflows the memory)
You just need to create a system temporary table in the database to perform the operation you are trying to do. It is highly recommended to create temporary tablespaces (user and system) like SMS type, or automatic type for recent versions. Make sure the pagesize is the correct one.

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'

Aurora PostgreSQL Temporary storage issue for index creation

We have migrated some of the data to PostgreSQL from MS-SQL Server. And are using R6G.Large aurora PostgreSQL RDS instance. We have transferred the data using DMS to PostgreSQL instance, and table size is around 183 GB and it has around 1.5 billion records. Now we are trying to create a Primary Key on an Id column, but it is failing with the below error...
ERROR: could not write to file "base/pgsql_tmp/pgsql_tmp18536.30": No
space left on device CONTEXT: SQL statement "ALTER TABLE
public.tbl_actions ADD CONSTRAINT tbl_actions_pkey PRIMARY KEY
(action_id)" PL/pgSQL function inline_code_block line 10 at SQL
statement SQL state: 53100
When looked at the documentation we found that index creation will use the temporary storage of the instance, and for r6g.large has 32 GiB. And for this huge table, that storage is not sufficient hence the index creation is failed with above error.
Is there any workaround to solve this without having to upgrade the instance type, may be by changing some values in parameter group or options groups.
To me, this looks like the storage has run out and not the RAM. You can check this using the Monitoring tab under the heading "Free Storage Space" on the RDS instance in AWS Console.
Try this:
To increase storage for a DB instance
Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/.
In the navigation pane, choose Databases.
Choose the DB instance that you want to modify.
Choose Modify.
Enter a new value for Allocated storage. It must be greater than the current value.
More details here:
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.Storage
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Troubleshooting.html#CHAP_Troubleshooting.Storage

Postgres SQL Query about database and table space

What is the hierarchy of Database related objects in postgres SQL?
Should it be like, table space must be created at instance level unlike other RDBMS(where we have table space under database).
If so we create the table space at instance level, what is the purpose of database? and what is difference between table space and database on postgres server?
An instance (in PostgreSQL called cluster) is a data directory initialized with initdb with a PostgreSQL server process.
A tablespace is a directory outside the data directory where objects can also be stored. Tablespaces are useful for certain corner cases like distributing I/O or limiting space for a subset of the data.
A database is a container for objects with permissions, organized in schemas.
The difference is that tablespaces are a physical concept, it defines a space where the data are stored, while databases are a logical concept about how data are organized, what they mean, how they are related, who is allowed to access them and so on.
The two concepts are orthogonal.
A database can have tables in several tablespaces, and a tablespace can contain data from several databases.
Database is where you organize all your objects. Tablespace is just storage space for those object.
You can storage your db object in different Tablespace. For example one table is storage in a Tablespace in diskA but another Table use a Tablespace in diskB to improve the performance. Or maybe you need a tablespace for big tables and dont mind use a slow big HDD for those objects.

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.