postgres on docker

Accessing Docker Postgres from host application

Accessing Docker Postgres in the host application

Accessing docker postgres is was easier with right commands. Docker has been a life saver for most of us – no doubt on that. We can do any kind of software interaction from host machine or from other docker container with bliss.

Once you have the docker postgres up and running, access docker postgres and use it for multiple of your projects. Here I will show how to access docker postgres from host machine. That is the same thing as any other app to access it as well.
Continue reading Accessing Docker Postgres from host application

postgres not null

Format output of postgres from psql

Format output of postgres – this is like \G in mysql

If you are looking for the \G equilvalent of the mysql in postgres, then here is what you are looking for:

On the psql terminal just do the following


\x auto;

This will prepare whatever you are going to display on the terminal to have the right output

here is an example of out formatted or nice output when you issue the command


infohub=# select * from help;
-[ RECORD 1 ]+--------------------------------------------------------------------------------------------------------------------------------------
id           | 1
date_created | 2018-08-18 09:58:54.774
message      | use \x auto command to get output printed nicely
title        | how to show the select output nicely formatted in psql
member_id    | 1
-[ RECORD 2 ]+--------------------------------------------------------------------------------------------------------------------------------------
id           | 2
date_created | 2018-08-18 10:41:46.979
message      | postgres has a nice output format option as well.
title        | An equivalent of \G nice format in mysql in postgres
member_id    | 1

As it can be seen above, the output is nice and easy to navigate than a bulky columns here and there.

postgres not null

psql select not working

PSQL Select not working – or other simple commands not working

Working with command line postgres tool psql and having an issue?

Why doesn’t the psql command show the simple select query?

PSQL select not working is a problem that can happen in either of the following scenarios:

  1. Are you on the right database?
    Chances are you might not be on the right database at all and the relation you are trying to find might not be there at all:Check if you are on the right database.
     
    Run the command \l to see the available databases.How to connect to the postgres database from the list?
    Use the command \c database_name
    Let’s say the database name is inventory then:\c inventory will connect you to the right database
  2. Continue reading psql select not working