0

I am trying to run some PostgreSQL command after creating the PostgreSQL.

First I tried to run the psql command line on my command prompt and it works. See below screenshot

enter image description here

The same I would like to do from terraform so added below code and it worked. Which means that psql command is able to connect to the server.

enter image description here

Now the next step is to execute some command. Every time I try to run command getting "The system cannot find the file specified." error. See below screen

enter image description here

Updated(11/27): After doing hours of research below worked for me

enter image description here

0

1 Answer 1

0

Now the next step is to execute some command. Every time I try to run command getting "The system cannot find the file specified." error.

The error "The system cannot find the file specified" typically indicates that the psql command is unable to locate the specified file.

enter image description here

Here is a PL/pgSQL command syntax to check the table in the database. For more details, refer to the PLSQL doc

'SELECT * FROM <table-name>; 

Here is the updated Terraform code for executing psql commands using Terraform.

    provider "azurerm" {
      features {}
    }

    resource "null_resource" "db_setup" {
      provisioner "local-exec" {
        command = "psql -h databasename.postgres.database.azure.com -p 5432 -U user -d postgres -c 'SELECT * FROM student;'"
        environment = {
          PGPASSWORD = "xxxxx"
        }
      }
    }

Terraform result:

enter image description here

Plsql command result

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for detailed answer but I updated my question with working solution

Your Answer

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.