How to set "\pset null (null)" by default? - psql

To make psql display NULL properly, I can do one of the followings:
(1) Execute \pset null (null) every time
(2) Start psql with -P 'null=(null)'
Any better way?

There are two ways.
(1) Use ~/.psqlrc config file. Simply put \pset null (null) inside the file.
(2) Create an alias in .bashrc in Linux or .bash_profile in MacOS, for example: alias psql="psql -P 'null=(null)'"

Related

Why does my docker image keep crashing when I try and build it due to a syntax error that is not making sense?

I am trying to build a mysql container using a docker file and an SQL file to create the tables but I keep getting this error in my terminal:> [3/3] RUN /docker-entrypoint-initdb.d/books.sql: #7 0.686 /docker-entrypoint-initdb.d/books.sql: line 1: syntax error near unexpected token`('
'7 0.686 /docker-entrypoint-initdb.d/books.sql: line 1: ``CREATE TABLE "articulos" (`
where it says I have a "`" in from of CREATE and I don't why that's showing up.
here is my docker file
FROM mysql:latest
ENV MYSQL_DATABASE books
COPY ./sqlscript /docker-entrypoint-initdb.d/
RUN /docker-entrypoint-initdb.d/books.sql
and this is my SQL file
CREATE TABLE "articulos" (
"id" int NOT NULL AUTO_INCREMENT,
"titulo" text,
"contenido" text,
"fechacreacion" date DEFAULT NULL,
"categoria" text,
PRIMARY KEY ("id")
) ENGINE=InnoDB AUTO_INCREMENT=143 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
Thank you in advance.
The RUN keyword is to execute a command. The SQL schema file isn't an executable. If you look at the documentation for the MySQL container, it should automatically load all schema files located in /docker-entrypoint-initdb.d when it first starts. So you really just need the following:
FROM mysql:latest
ENV MYSQL_DATABASE books
COPY ./books.sql /docker-entrypoint-initdb.d/
...and make sure your SQL file is named books.sql in the current working directory. (Not sure what sqlscript is in your original question).
You could be facing two problems:
Docker is trying to run your .sql file as if it was a bash script
And anyway, your MySQL server might not be running when building
Try removing your last Dockerfile line (RUN /docker-entrypoint-initdb.d/books.sql ).
It might work like you want it to since I presume that .sql files placed in the /docker-entrypoint-initdb.d/ directory are executed on startup.

npx typeorm migration:create -n TestData Dosen't create a migration

enter image description here
I wasn't able to create a migration even after following doc.
Since the update (I don't know which, exactly), the flag -n was replaced by -o.
So, now you need to run.
typeorm migration:create -o path/to/my/migration
If you are using multiple datasources
migration:create doesn't work with specific datasources, so
I reccomend you to add two scripts in "scripts" session at package.json like the following:
default typeorm (that you will use for non-specific database stuff):
"typeorm": "ts-node-dev ./node_modules/typeorm/cli.js"
your custom typeorm (that you will use for your specific database stuff, like run & revert migrations):
"myTypeorm":"ts-node-dev ./node_modules/typeorm/cli.js -d path/to/my/ormconfig.ts"

Hyperledger Explorer

I have installed all prerequisites for setting up the hyperledger Explorer but when I start it, I got the following error in log file:
And my config.json file is this:
Postgres' command also done:
1: https://i.stack.imgur.com/eTpSY.png
2: https://i.stack.imgur.com/IocQU.png
You're database setup is not done correctly, run these commands one by one.
Database setup
Connect to PostgreSQL database
sudo -u postgres psql
Run create database script
\i app/db/explorerpg.sql
\i app/db/updatepg.sql
Run db status commands.
\l view created fabricexplorer database
\d view created tables
Actually it postgres database error ...
In your error its clearly said that the chaincode_id doesnt exit ... so this is the problem .
if you want check what column are existed in the transaction table just follow below step
cd blockchain-explorer/app/persistence/postgreSQL/db
sudo -u postgres psql
\d transactions
check the corresponding column chaincode_id exist or not (it wont exist now ,Thats why you got this error)....
Solution for this type error
If you got any error like this first just go to the blockchain-explorer/app/persistence/postgreSQL/db directory
There you can see two file explorerpg.sql and updatepg.sql open this two file and check the corresponding column if existed on any of this file or not. If not you better to download explorer another version which contain the corresponding columns either of this two file mentioned above.
if existed just run below command on ubuntu
cd blockchain-explorer/app/persistence/postgreSQL/db
sudo -u postgres psql
\i explorerpg.sql
\i updatepg.sql
Once done this command just check the column "chaincode_id " is created or not by
\d transactions
it will list all column just check it on.
if the chaincode_id is exist run the explorer again ....

cluster.properties file getting jira.node.id ID automatically, like the hostname

I would like to edit the cluster.properties file to the parameter jira.node.id gets an ID automatically, for example the hostname.
It is possible? If so, how?
Thanks in advance!
I got it.
Basically I created a bash script to add automatically the hostname in the file. Something like this:
HOST=$HOSTNAME
JIRANODE="jira.node.id = "$HOST
sed -i "2s/./$JIRANODE/" /var/atlassian/application-data/jira/cluster.properties*
This bash is executed in every reboot via cron.

Postgresql fails to be recognised on the correct path

I'm trying to setup a new app with postgresql so I can deploy with Heroku. However, when I run the app using 'rails server' my welcome to rails screen gives this error:
PG::Error
could not connect to server: Permission denied Is the server running
locally and accepting connections on Unix domain socket
"/var/pgsql_socket/.s.PGSQL.5432"?
I'm sure this is the same issue as is covered here:
Repairing Postgresql after upgrading to OSX 10.7 Lion
But the fix by John Wang doesn't work.
I've tried adding 'export PATH=/usr/local/bin:$PATH' to the .bash_profile, .bashrc and .zshrc, none of which change the outcome. Calling which psql always returns /usr/bin/psql.
What am I doing wrong here? Any help would be much appreciated!
edit
Running /usr/local/bin/psql gives the same error and running echo $PATH gives:
/opt/local/bin:/opt/local/sbin:/Users/dave/.rvm/gems/ruby-1.9.3-p194/bin:/Users/dave/.rvm/gems/ruby-1.9.3-p194#global/bin:/Users/dave/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/dave/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Users/dave/.rvm/bin
What happens if you run your locally installed psql directly?
/usr/local/bin/psql ...
If that works then it's the path you need to change. You can just try running the export in a terminal, then which psql. If that doesn't pick up the right psql then check the export worked with
echo $PATH
I'm not sure which .xxrc file you'll need to update then - not got a mac to hand I'm afraid, but at least you'll know the command will work.
Oh - I keep several different versions of PostgreSQL around and find it useful to have some aliases set up:
alias psql90='/usr/local/pgsql90/bin/psql -p 5490'
alias psql84='/usr/local/pgsql84/bin/psql -p 5484'
alias pg_dump90=...
Your $PATH is just a list of directories to check separated by ":". It starts /opt/local/bin rather than /usr/local/bin and if you look further along you'll see /usr/bin coming before /usr/local/bin. So - we need to do two things:
Find out which psql we actually want
Make sure we can edit our PATH
Firstly - find your postgresql.conf file and check what port you are running on. There are three items of interest: listen_addresses, port and unix_socket_directory. Then we'll see if there's a socket there.
ls -a <your unix_socket_directory>
You should see a "file" something like ".s.PGSQL.5432" where the 5432 is the port number from your config file. If there's no such file, it's not running and it's time to get it running. You may need to change the port number in the config file if it matches Apple's existing usage.
Then find what psql installations exist
find /usr -type f -name psql
find /opt -type f -name psql
Try and figure out which one you need, perhaps add --version to help.
Then, let's see about editing your PATH. You must have some changes in your settings file anyway, so let's see if we can find where that setting is.
grep -l 'local/bin' ~/.*rc
That should list filenames containing local/bin - have a look and see if they are editing your PATH.

Resources