Issue running Postgresql 9.6 backup (pg_dump/pg_dumpall) - database

I have a postgreSQL 9.6 installation on Ubuntu 16.04, provided by the EnterpriseDB. I've been connecting to the local server and using it for a number of months. I figured I should backup the server at this point, so I tried using the pg_dump command as follows:
cd to postgres bin at /opt/PostgreSQL/9.6/bin
Run pg_dump via sudo pg_dumpall > /sata_ssd2/pgdump/0419.bkp
This gives an error: Error: You must install at least one postgresql-client-<version> package. I tried installing via: sudo apt-get install postgresql-client-9.6 but that package does not seem to exist.
I also tried to run pg_dump and pg_dumpall via pgAdmin4. It first made me fill in the binary paths for EDB Advanced Server Binary Path and PostgreSQL Binary Path; I put in opt/PostgreSQL/9.6/bin/, which is where the pg_dump executable is. When I tried to run the backups, I got the error: 'ascii' codec can't decode byte 0xe1 in position 1: ordinal not in range(128). I found an answer to this elsewhere that recommended changing from client_encoding = SQLascii to client_encoding = utf8 in postgresql.conf, but this did not help.
Does anyone have any advice on where to go from here?

In a unix/linux system the current directory . is not on the PATH and not searched for binaries.
If you want to run the command pg_basebackup in /opt/PostgreSQL/9.6/bin/, you run /opt/PostgreSQL/9.6/bin/pg_basebackup.
If you did want to run the command pg_basebackup that you knew was in the current directory you could write ./pg_basebackup instead. But just using the full path rather than cding unnecessarily is better.

Related

"bash: sed: command not found" RHEL7 when installing SQL Server

NEED HELP - LINUX NEWBIE - BROKEN LINUX RHEL7
While installing the mssql-tools on RHEL7 and following instructions to add the path for the mssql-tools, we added the following commands:
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
After rebuilding the server for a second time, I've reached this Microsoft step again. As it is the cause for my broken copy of RHEL7, having a way to do this properly and not incorrectly as listed above would be helpful. Most articles list about 50 ways to do this. I'm looking for one way only and it will be nice if the one way actually works and I don't spend another part of my life rebuilding the server again.
https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat?view=sql-server-ver15
I created an issue in Github for this failing.
https://github.com/MicrosoftDocs/sql-docs/issues/7288
The article listed here seems to do the trick
https://dba.stackexchange.com/questions/174277/getting-sqlcmd-sqlcmd-command-not-found-in-linux
Long and short is the PATH should work as a join if it works like it does in Windows but I wound up using
sudo ln -s /opt/mssql-tools/bin/* /usr/local/bin/
to join that location with the user bin. There is probably more to it since security is always number one, but at least I was able to complete the installation of SQL Server on the RHEL7 release.

MSSQL: The configuration file '/var/opt/mssql/mssql.conf' failed to load (Ubuntu)

I have an issue to install MSSQL on my Linux(Ubuntu 16.04) Server.
I have used the manual from Microsoft but I always fail on the same stage.
Actually, Docker is not an alternative due to Kernal issues.
After:
sudo apt-get install -y mssql-server
I'm supposed to do
sudo /opt/mssql/bin/mssql-conf setup.
This returns after answering all questions:
sqlservr[8383]: sqlservr: The configuration file '/var/opt/mssql/mssql.conf' failed to load (error: The INI file could not be opened. Errno [2] Filename [mssql.conf]).
I can access the config file and it seems to be usable by the script as well.
My Linux skills are not good enough to resolve this issue.
To answer some questions that were raised:
I tried sudo
cat the file returns the content as expected
Try running mssql server as root first (stop the service, run it as root, with /opt/mssql/bin/sqlservr) and see if it works that way. If it does, stop the mssql server and fix the ownership of the mssql dir with sudo chown -R mssql:mssql /var/opt/mssql). More info on this answer.

postgreSQL error initdb: command not found

i was installing postgresql on ubuntu using linuxbrew:
brew install postgresql
it seems to work fine but after that because i was installing PostgreSQL for the first time i tried creating a database:
initdb /usr/local/var/postgres -E utf8
but it returned as:
initdb: command not found
i tried running the command with sudo but that doesn't helped
run locate initdb it should give you the list to chose. smth like:
MacBook-Air:~ vao$ locate initdb
/usr/local/Cellar/postgresql/9.5.3/bin/initdb
/usr/local/Cellar/postgresql/9.5.3/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.5.3/share/man/man1/initdb.1
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
/usr/local/Cellar/postgresql/9.6.1/share/doc/postgresql/html/app-initdb.html
/usr/local/Cellar/postgresql/9.6.1/share/man/man1/initdb.1
/usr/local/bin/initdb
/usr/local/share/man/man1/initdb.1
So in my case I want to run
/usr/local/Cellar/postgresql/9.6.1/bin/initdb
If you don't have mlocate installed, either install it or use
sudo find / -name initdb
There's a good answer to a similar question on SuperUser.
In short:
Postgres groups databases into "clusters", each of which is a named collection of databases sharing a configuration and data location, and running on a single server instance with its own TCP port.
If you only want a single instance of Postgres, the installation includes a cluster named "main", so you don't need to run initdb to create one.
If you do need multiple clusters, then the Postgres packages for Debian and Ubuntu provide a different command pg_createcluster to be used instead of initdb, with the latter not included in PATH so as to discourage end users from using it directly.
And if you're just trying to create a database, not a database cluster, use the createdb command instead.
I had the same problem and found the answer here.
Ubuntu path is
/usr/lib/postgresql/9.6/bin/initdb
Edit: Sorry, Ahmed asked about linuxbrew, I'm talking about Ubuntu.
I Hope this answer helps somebody.
I had a similar issue caused by the brew install postgresql not properly linking postgres. The solve for me was to run:
brew link --overwrite postgresql
you can add the PATH to run from any location
sudo nano ~/.profile
inside nano go to the end and add the following
# set PATH so it includes user's private bin if it exists
if [ -d "/usr/lib/postgresql/14/bin/" ] ; then
PATH="/usr/lib/postgresql/14/bin/:$PATH"
fi
and configure the alternative
sudo update-alternatives --install /usr/bin/initdb initdb /usr/lib/postgresql/14/bin/initdb 1

Deploy the database to Docker Container microsoft/mssql-server-linux

I have a database running on SQL Server (13.01) on Windows. I like to deploy it to the Docker Container on Linux using SSDT.
I can perfectly connect to the server running on Docker and create/drop database manually and play with the data.
The problem is I can not publish it. I'm executing following script on Powershell
PS: SqlPackage.exe /Action:Publish /SourceFile:"d.dacpac" /TargetConnectionString:"server=containeraddress;database=thedatabase;user id=sa;password=thepassword;
and getting the following error.
Unable to connect to master or target server 'the database'. You must have a user with the same password in master or target server 'the database'. (Microsoft.Data.Tools.Schema.Sql)
I have the same user and same password on target and source servers.
Is there anybody has the same problem and know how to solve it?
I'll post this here as most of the answers refer to having an existing compiled dacpac file, which may not always be possible. I haven't seen similar ideas posted elsewhere to the solution I'm suggesting here.
Given your usage of docker and if you wish to compile your visual studio project inside the container, given certain combinations of the container base OS and image may not be possible to create a dacpac file with msbuild.
You can work around restoring the database using a series of unix based commands, taking note that the visual studio database project is usually just a series of SQL files, below I show an example of this, where I concat the SQL files into a single file and call sqlcmd to run the script;
FROM mcr.microsoft.com/mssql/server
WORKDIR /init
ENV ACCEPT_EULA=Y
ENV MSSQL_SA_PASSWORD=MyPassword
EXPOSE 1433:1433
RUN apt-get update && apt-get install dos2unix
COPY /solution_folder/database/Tables/*.sql /init/
WORKDIR /database
RUN echo "CREATE DATABASE [database_name];\nGO\nUSE [database_name];\n” >> /database/create.sql
RUN for f in /init/*.sql; do dos2unix $f; cat $f >> /database/create.sql; echo "\nGO\n" >> /database/create.sql; done
RUN ( /opt/mssql/bin/sqlservr --accept-eula & ) | grep -q "Service Broker manager has started" && /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ‘MyPassword’ -i /database/create.sql && pkill sqlservr
The reason for "dos2unix" is that the SQL files created within visual studio have unique hidden cr/lf (and other characters) which the linux version of sqlcmd won't interpret successfully and will cause errors (which is kind of bizarre and this is exactly the kind of thing you'd want a cross platform database to be able to cope with)
Also, within the final run command you have to start-up the sql server service temporarily otherwise you'll also get errors; it's a little bit of work-around, and a bit fiddly and I'm not sure entirely that the microsoft sql server linux container is well designed enough for the simple task of restoring a database like this, the nuances are the differences between building and running a container and needing some sort of happy middle ground of both concepts for it to work.
Given here isn't a complete solution to restore, it only deals with Tables from the project file, although it should be trivial to expand to scalar functions and stored procedures.
Which version of SqlPackage.exe are you using? Only the most recent release candidate versions of SqlPackage.exe support SQL Server vNext CTP. The SqlPackage release candidate can be downloaded here: https://www.microsoft.com/en-us/download/details.aspx?id=54273

installing postgres 9.2 on Mac OSX 10.6 with KyngChaos package

I'm trying to install postgres 9.2 on a mac 10.6 using using KyngChaos (because ultimately I'd like to enable PostGIS, and this seems to be the best package to that with).
I get exactly the problem spelled out at the bottom of the page: http://www.kyngchaos.com/software/postgres
--
NOTE: I've had reports of the installer not initializing the data cluster, which results in Postgres not starting. It seems to be random, and I haven't figured out the cause yet. If Postgres won't start (you get an error "could not connect to server: No such file or directory" when trying to connect with psql), try manually initializing the cluster with:
/usr/local/pgsql-9.1/bin/initdb -U postgres \
-D /usr/local/pgsql-9.1/data --encoding=UTF8 --locale=en_US"
Or see the Locales and Encodings readme if you need a different locale or encoding.
Then stop and start Postgres as specified in the readme.
--
I run
/usr/local/pgsql-9.1/bin/initdb -U postgres -D /usr/local/pgsql-9.1/data --encoding=UTF8 --locale=en_US"
which opens up a new line to enter additional commands with
>
but i'm lost there, even after combing the readme.

Resources