Score:0

Can't run psql backup in user-data script in AWS EC2

ph flag

I have private subnet for my EC2 instance, I use NAT Gateway for it to access internet. I created user-data script for my EC2 where I've created docker-compose.yml with postgres service defined. After defining this i have:

docker-compose up -d
# i use terraform for ${PGPASSWORD} template variable
export PGPASSWORD="${PGPASSWORD}"
psql -h localhost -U my_user -p 5432 -d my_db < ./mydump.sql

Inside EC2 I already have mydump.sql file. The problem here it gives me error for psql like this:

psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed: server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request.

I can't understand why. Although my postgres container is up and LOG: database system is ready to accept connections. Can someone help with this?

Maybe this problem relates to root under which user-data script is executed and session closes so it interrupts connection for psql. Or this relates to docker and port-forwarding. Can't understand the reason actually

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.