I have dozens of legacy stored procedures which create temporary tables inside for collecting results for a read-only application.
I've created a read-replica of my PostgreSQL in Amazon RDS and tried to perform this procedures, but failed, as it doesn't allow to create even temporary tables in a read-only transaction.
Are any ways how to solve this issue with minimal efforts?
-
Move those queries to the master. PostgreSQL currently does not allow creating temporary tables on read-only replicas, this is not an RDS specific issue.András Váczi– András Váczi2016年10月14日 08:56:24 +00:00Commented Oct 14, 2016 at 8:56
-
@dezso Great advice, read please my question more carefully: these procedures are used for reading data and I can not change DB type, only read-replicaAndremoniy– Andremoniy2016年10月14日 09:37:13 +00:00Commented Oct 14, 2016 at 9:37
-
Eh, you are right, as the way of maintaining a replica is different in RDS than in plain PostgreSQL, it is an RDS specific issue, with its effect being very similar in both cases :D Unfortunately for you, read replicas are also read-only, so no temp tables there.András Váczi– András Váczi2016年10月14日 09:39:54 +00:00Commented Oct 14, 2016 at 9:39
1 Answer 1
As the most easy way which I found to solve this issue - is wrapping all "temporary tables" into separate stored procedures, which return TABLE(...)
type, and then use Common Table Expressions (https://www.postgresql.org/docs/9.1/static/queries-with.html).
-
How much work it will be to rewrite those functions?András Váczi– András Váczi2016年10月14日 11:54:00 +00:00Commented Oct 14, 2016 at 11:54
-
2-4 hours. I've already did it :) Look, I have no choice.Andremoniy– Andremoniy2016年10月14日 11:59:02 +00:00Commented Oct 14, 2016 at 11:59
-
1So you didn't have hundreds of them, that's good news :DAndrás Váczi– András Váczi2016年10月14日 12:18:11 +00:00Commented Oct 14, 2016 at 12:18
Explore related questions
See similar questions with these tags.