1

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.

asked Jan 27, 2022 at 10:21
1

1 Answer 1

2

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.

answered Jan 31, 2022 at 18:26
1
  • 1
    Using different credentials might help to prevent the oops case ;). Commented Feb 1, 2022 at 6:56

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.