From within a plpgsql script run on an Amazon RDS Postgres instance, is it possible to get information about instance configuration? How do I retrieve the DB instance ID, ARN (Amazon Resouce Name) or Endpoint of the instance?
I want to use it as a check inside some plpgsql-script to make a 100% sure it's not going to do its thing on the production database.
-
I found this: dba.stackexchange.com/questions/217255/… although it only gives me the server ip address and not the hostnameChristiaan Westerbeek– Christiaan Westerbeek2022年02月02日 09:39:04 +00:00Commented Feb 2, 2022 at 9:39
1 Answer 1
Unlike the EC2 instances and ECS Tasks (EC2 Based/Fargate Based) there is no metadata service that you are able to query to provide you with those details. The best that you will be able to get would be from system level views that might provide the hostname. However I would use caution with relying on that information as in a fully managed environment failovers and instance replacements happen automatically 99% of the time so the values you query could might be different the next time and may or may not have a standard nomenclature to them.
The only way to get that information is to make a call to the RDS API endpoint for the cluster and/or instance that you are looking for.
If you are running the sql via an external process that will connect to the instance you could put those checks as a prerequisite to connecting and running the script. However if you are manually run the script by connecting directly to the instance and hoping to prevent an "oops" action it's going to be up to the person taking the action to check their work.
-
1Using different credentials might help to prevent the oops case ;).Tim– Tim2022年02月01日 06:56:43 +00:00Commented Feb 1, 2022 at 6:56
Explore related questions
See similar questions with these tags.