How do I make a script that properly introduces hstore in both 9.0 and 9.1? - postgresql-9.1

I am trying to introduce the hstore type into the database of a project I'm developing. But the problem is that I have a slightly newer version of the Postgres server installed on my development machine than there is on the production machine. While I can simply execute the CREATE EXTENSION command locally, this command is unavailable on the production machine.
Is there a way to create a script that will install hstore both on 9.1 and 9.0?

For 9.0, you could use a script like this (ex: create_hstore.sh):
#!/bin/bash
DB=$1
ARGS="-U postgres -h localhost"
CONTRIB=/usr/pgsql-9.0/share/contrib
[ $# -lt 1 ] && exit 1
# Uncomment following lines if necessary
#createdb $ARGS $DB
#createlang $ARGS plpgsql $DB
psql $ARGS -f $CONTRIB/hstore.sql $DB
and then to invoke it:
./create_hstore.sh <db_name>

... if there was a way to determine which PG version is currently installed in the system.
Ask Postgres:
psql -c 'select version()' postgres
Or, if you are confident that the version of psql is in sync:
psql --version

Related

How to use placeholders prefix in flyway command line

Originally posted in https://github.com/flyway/flyway/issues/2429
I have an issue (probably a wrong configuration) using flyway placeholders; I can use placeholders for my own variables; but it fails cos one value in an sql query has a similar syntax as flyway placeholder syntax.
Which version and edition of Flyway are you using?
5.2.4 using official docker image
If this is not the latest version, can you reproduce the issue with the latest one as well? (Many bugs are fixed in newer releases and upgrading will often resolve the issue)
5.2.4 tag is the latest version in docker hub (https://hub.docker.com/r/boxfuse/flyway/)
Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)
Command line thru the docker image
Which database are you using (type & version)?
MySQL Server version: 5.7.26 - MySQL Community Server (GPL) - This is a legacy project
Which operating system are you using?
Linux CentOS 7 x64 (uname -r = 3.10.0-957.5.1.el7.x86_64)
What did you do?
(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)
I apply flyway to initialize/update a MySQL database; here are a couple of SQL commands.
Here I use placeholders with xxx prefixes:
CREATE USER IF NOT EXISTS '${xxxdbuser}'#'${xxxdbclip}' IDENTIFIED WITH mysql_native_password BY '${xxxdbpass}';
GRANT ALL PRIVILEGES ON ${xxxdbbase}.* TO '${xxxdbuser}'#'${xxxdbclip}';
FLUSH PRIVILEGES;
... then in another SQL script, from a thirdparty app, I insert a content with ${row}. I don't want Flyway to interpret ${row} as a placeholder, only my own vars starting by ${xxx such as ${xxxdbuser}
INSERT INTO `xxx_xxx` (`name`, `template`, `lang`, `group`, `version`, `data`, `size`, `style`, `modified`) VALUES
... ('addressbook.email.rows', '', '', 0, '1.3.001', 'a:1:{i:0;a:6:{ ... \"label\";s:21:\"$row_cont[type_label]\";s:4:\"name\";s:12:\"${row}[type]\";s:5:\"align\";... :{i:0;s:4:\"100%\";}}}', '100%', '', 1150326789), ...
I guess the placeholderPrefix parameter described into https://flywaydb.org/documentation/commandline/info or FLYWAY_PLACEHOLDER_PREFIX env var described into https://flywaydb.org/documentation/envvars#FLYWAY_PLACEHOLDER_PREFIX is for that purpose; but I didn't succeed in using them!
Here is my command using docker:
docker run --rm --network="$(docker network ls --filter name=app_mysql_dev --filter "label=type=app" --format '{{.ID}}')" \
-v `pwd`/code/Admin/install:/flyway/sql \
-e FLYWAY_URL=jdbc:mysql://${host}:${port}?useSSL=false \
-e FLYWAY_SCHEMAS=${base} \
-e FLYWAY_USER=root \
-e FLYWAY_PASSWORD=${root_pwd} \
-e FLYWAY_PLACEHOLDERS_PREFIX="\${xxx" \
-e FLYWAY_PLACEHOLDERS_XXXDBBASE=${base} \
-e FLYWAY_PLACEHOLDERS_XXXDBUSER=${user} \
-e FLYWAY_PLACEHOLDERS_XXXDBPASS=${pass} \
-e FLYWAY_PLACEHOLDERS_XXXDBCLIP=${clip} \
-e FLYWAY_PLACEHOLDERS_XXXVHOST=${vhost} \
-e FLYWAY_PLACEHOLDERS_XXXSCHEME=${scheme} \
-e FLYWAY_CONNECT_RETRIES=5 \
boxfuse/flyway:5.2.4 -locations=filesystem:/flyway/sql/custom/ \
migrate
What did you expect to see?
All ${xxx placeholders should be replaced by their corresponding ENV values; and the ${row} chain in SQL code stay unchanged.
What did you see instead?
Flyway error:
Flyway Community Edition 5.2.4 by Boxfuse
Database: jdbc:mysql://tasks.atlas-mysql:3306 (MySQL 5.7)
ERROR: No value provided for placeholder expressions: ${row}. Check your configuration!
I guess I did not configure my command correctly... any help, advise and/or command line example would help.
Regrads,
Chris
I think there are a couple of problems in your command:
-e FLYWAY_PLACEHOLDERS_PREFIX="\${xxx"
should be FLYWAY_PLACEHOLDER_PREFIX (no S), and
-e FLYWAY_PLACEHOLDERS_XXXDBBASE=${base}
should be FLYWAY_PLACEHOLDERS_DBBASE (as XXX is part of the prefix, it's not included in the placeholder name; and analogously for following lines).

"mysql -V" and "select version()" show different versions

First of all, thanks a lot for your time!
I upgraded MariaDB on Ubuntu 18.04 and restarted: sudo systemctl restart mysql.server several times.
When I run command mysql -V it shows:
mysql Ver 15.1 Distrib 10.3.14-MariaDB, for debian-linux-gnu (x86_64)
using readline 5.2
When I run query SELECT VERSION(); it shows:
10.1.38-MariaDB-0ubuntu0.18.04.1
Any help would be appreciated.
The mysql executable you have installed has a different version than the server it connects to.
Make sure you are connecting to the correct server. Sometimes the configuration defaults file points you automatically to a remote server.
Check where the mysql executable is found from using command -v mysql or which mysql. Most of the time the binary is located in /usr/bin/mysql so you might try invoking that directly to see if that helps.

Alfresco server gets startup gets hung

I am trying to start a Alfresco server but it got hung in between,Please see below screenshot, I have copied Alfresco instance from one server to another server, I have also made necessary changes in Alfresco-global.properties.
Please help on this
For backup of your database and alf_data you can download and run the following script.
http://www.contcentric.com/alfresco-backup/
Note: you will have to manually backup the indexes from the solr4 folder and other customizations (like amps and jar deployed)
Follow the alfresco restore steps
1. Install new alfresco instance. Do not start server
2. Start postgresql using the following command
./alfresco.sh start postgresql
3. Go to the <ALF-HOME>/postgresql/bin
4. Run the following commmand
psql -U alfresco -h <hostname> -p port
e.g. psql -U alfresco -h localhost -p 5422
5. It will ask you to set the password, enter the password and remember it
6. Run the following command
psql -U alfresco -h <host> -p port <dbname> < dumpFile
e.g. psql -U alfresco -h localhost -p 5422 alfresco < /opt/migration-backup/01-10-2018-15-54-47/database/alfresco_db_dump
7. You will notice the multiple tables and index are created
8. Start the tomcat using the following command
./alfresco.sh start tomcat
9. Test your migration.

Airflow installation issue on Windows 7

How to install Airflow on Windows 7? getting below error while installing it using pip install apache-airflow :
---------------------------------------- Command "c:\users\shrgupta5\appdata\local\programs\python\python36-32\python.exe
-u -c "import setuptools, tokenize;__file__='C:\\Users\\SHRGUP~1\\AppData\\Loca l\\Temp\\pip-build-_yptw7sa\\psutil\\setup.py';f=getattr(tokenize, 'open', open) (__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __fi le__, 'exec'))" install
--record C:\Users\SHRGUP~1\AppData\Local\Temp\pip-_cwm0n u7-record\install-record.txt --single-version-externally-managed
--compile" fail ed with error code 1 in C:\Users\SHRGUP~1\AppData\Local\Temp\pip-build-_yptw7sa\ psutil\
I wouldn't bother trying to install Airflow on windows, even after you install it successfully you cannot run the airflow script due to a dependency on the unix-only module pwd
You can run Airflow on Windows by using the Docker setup from puckel https://github.com/puckel/docker-airflow.
Use VirtualBox and Docker Toolbox(legacy) and setup a docker-machine on your Windows computer (docker-machine create -d virtualbox --virtualbox-cpu-count "2" --virtualbox-memory "2048" default)
make sure to fork puckels git repo underneath c:/Users/yourusername/documents otherwise mounting of DAGS won't work
You should now be able to spin up Airflow e.g. by using the celery-executor setup with docker compose -f docker-compose-CeleryExecutor.yml up -d
I have setup a environment where I develop the DAGs on Windows, test them within the dockercontainer and then push the Dockerimage to Linux to production. I have added a more detailed tutorial here.
Airflow cannot be installed on Windows within the standard command prompt.
You need to use bash and afterwards change the config:
How to run Airflow on Windows
Download the source of airflow from pypi:
https://pypi.org/project/airflow/#files
Unzip and edit setup.cfg, then go to the install_requires section and change the version of psutil with the following: 'psutil>=5.4.7',
Finally, run python setup.py install in the source directory

macports apache2 install missing pdo drivers

I just switched to a macports apache2 install in order to get imagemagick. Now that I have imagemagick, my pdo sqlite no longer works :-( I've done some research and, of course, the sqlite pdo driver is meant to be enabled by default.
Some info:
The error is: <b>Fatal error</b>: Uncaught exception 'PDOException' with message 'could not find driver' in ....
The code is: $dbh = new PDO("sqlite:db.sqlite");
Some phpInfo:
PHP Version 5.3.25
Configure Command ... '--enable-pdo' ...
PDO
PDO support enabled
PDO drivers no value
command line: php -i | grep -i pdo outputs:
Configure Command => './configure' [...] '--enable-pdo' [...]
PDO
PDO support => enabled
PDO drivers =>
in /opt/local/lib/php/extensions/.../ I have only imagick.so (perhaps I should have an sqlite.so?)
Please let me know if any other info would be useful, and I'll add it to the question.
Here is what worked for me:
sudo port install php5-sqlite
sudo port install php5 +apache2 +sqlite
The second line here didn't seem to do anything, but you never know.
After restarting I noticed I didn't have imagemagick, which I thought I already had, so
sudo port install php5-imagick
Now restarting apache2 the "macports" way:
sudo port unload apache2
sudo port load apache2
And looking at phpinfo, I have sqlite2 and sqlite (which, confusingly, is sqlite3) drivers enabled for pdo.

Resources