- Le plus récent
- Le plus de votes
- La plupart des commentaires
- In order to fetch the respective instance name (reader or writer) to which you are connected to, you can use below :- (please note you have to connect using cluster endpoint in order to get cluster name)
[userr@machine]$ psql -h database-3.cluster-xxxxx.region.rds.amazonaws.com -U postgres -d postgres
postgres=> SELECT :'HOST';
database-3.cluster-xxxxx.region.rds.amazonaws.com
-- The above output can be further trimmed to just have cluster name
postgres=> SELECT SPLIT_PART(:'HOST','.',1);
database-3
-- To use above as variable in function , following workaround can be used as ":" is considered as variable in the psql.
postgres=>create table host_name_tab (ht varchar); postgres=> insert into host_name_tab select :'HOST';
postgres=> create or replace function get_host() returns varchar language plpgsql as $$ declare host_name varchar; begin SELECT SPLIT_PART(ht,'.',1) into host_name from host_name_tab ; return host_name; end; $$;
postgres=> select get_host(); get_host
database-3 (1 row)
- If you which to get the instance name you are connected to you can use below :
postgres=> select aurora_db_instance_identifier() as host_name; host_name
database-3-instance-1-ap-south-1a (1 row)
Please note as this is development related query it can be achieved by different logic.
Contenus pertinents
- demandé il y a un an
- demandé il y a 8 mois
- demandé il y a un an
- AWS OFFICIELA mis à jour il y a 2 ans
I thought of a similar idea (manually inserting into a table like you did) in a shower epiphany. I think I will use this solution for it. It's an extra step, for sure, but it does solve the problem.
Thank you!