Installing PostgreSQL 9.2 with Chef postgresql - postgresql

I am struggling to get PostgreSQL 9.2 installed with the Opscode postgresql cookbook on a Vagrant VM (Ubuntu 12.04) .
This is the my recipe:
node.set['postgresql']['version'] = "9.2"
node.set['postgresql']['enable_pgdg_apt'] = true
node.set['postgresql']['password'] = {postgres: "pwd"}
node.set['postgresql']['server']['packages'] = ["postgresql-9.2"]
include_recipe "postgresql::apt_pgdg_postgresql"
include_recipe "postgresql::server"
include_recipe "database"
The run results in the following:
[2013-05-23T11:00:52+00:00] FATAL: Chef::Exceptions::EnclosingDirectoryDoesNotExist:
template[/etc/postgresql/9.2/main/postgresql.conf] (postgresql::server line 60) had an error:
Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /etc/postgresql/9.2/main does not exist.
I am using the latest 3.0.0 version of the poostgresql cookbook.
Rerunning everything from scratch with a clean VM (vagrant destroy, up, etc) gives this error:
[2013-05-23T11:16:37+00:00] FATAL: Chef::Exceptions::EnclosingDirectoryDoesNotExist:
template[/etc/postgresql/9.1/main/postgresql.conf] (postgresql::server line 60) had an error:
Chef::Exceptions::EnclosingDirectoryDoesNotExist: Parent directory /etc/postgresql/9.1/main does not exist.
Suddenly we don't even have the right version.

Here's what finally fixed it for me:
run update-alternatives --remove postmaster.1.gz /usr/share/postgresql/9.1/man/man1/postmaster.1.gz
Use the conf below.
Snip:
postgresql: {
enable_pgdg_apt: true,
dir: "/etc/postgresql/9.2/main",
config: {
data_directory: "/var/lib/postgresql/9.2/main",
hba_file: "/etc/postgresql/9.2/main/pg_hba.conf",
ident_file: "/etc/postgresql/9.2/main/pg_ident.conf",
external_pid_file: "/var/run/postgresql/9.2-main.pid",
ssl_key_file: "/etc/ssl/private/ssl-cert-snakeoil.key",
ssl_cert_file: "/etc/ssl/certs/ssl-cert-snakeoil.pem",
},
client: {
packages: ["postgresql-client-9.2",],
},
server: {
packages: ["postgresql-9.2", "postgresql-server-dev-9.2"],
},
contrib: {
packages: ["postgresql-contrib-9.2"],
},
password: {
postgres: 'postgres'
},
pg_hba: [
{type: 'local', db: 'all', user: 'all', addr: nil, method: 'trust'},
{type: 'host', db: 'all', user: 'all', addr: '127.0.0.1/32', method: 'trust'},
{type: 'host', db: 'all', user: 'all', addr: '::1/128', method: 'trust'}
],
version: "9.2",
},

I was able to fix this by setting the directory:
node.set['postgresql']['dir'] = "/var/lib/postgresql/9.2/main"
Looks like this is the same issue: http://tickets.opscode.com/browse/COOK-2113

Related

How can I start nest app with Postgress DB on Win 10?

I'm front dev and I need to test locally my front app with backend (nest js) and postgresql DB. Who can write me the right way How to run and connect to DB ? I get some errors on app start. I work on win 10 and there is my steps for start this app.
install postgresql
npm install for my nest js app
run pgAdmin4 and create DB for my app
npm start
There is my ormconfig
module.exports = {
"type": "postgres",
"host": process.env.POSTGRES_HOST || "localhost",
"port": process.env.POSTGRES_PORT || 5432,
"username": process.env.POSTGRES_USER || "", //<- Here I try to set all possible username
"password": process.env.POSTGRES_PASSWORD || "", //<- Here I try to set all possible password
"database": process.env.POSTGRES_DB || "my_database",
"entities": ["dist/**/*.entity{.ts,.js}"],
"synchronize": true,
"logging": true
}
There is error that I encountered
error
Also on other computer I try to do this and I get error like
[Nest] ERROR [TypeOrmModule] Unable to connect to the database.
FATAL: password authentication failed for user "postgres" (postgresql 14 with pgAdmin 4)
In your typeormconfig.ts , you should write this:
export class PostgresTypeormConfiguration implements TypeOrmOptionsFactory
{
createTypeOrmOptions(connectionName?: string): TypeOrmModuleOptions | Promise<TypeOrmModuleOptions> {
const TypeOrmOptions:TypeOrmModuleOptions=
{
type: "postgres",
host: process.env.POSTGRES_HOST ,
port: process.env.POSTGRES_PORT ,
username: process.env.POSTGRES_USER ,
password: process.env.POSTGRES_PASSWORD ,
database: process.env.POSTGRES_DB,
entities: ["dist/**/*.entity{.ts,.js}"],
synchronize: true,
logging: true
}
return TypeOrmOptions
}
}
and you should define this in your module like this:
#Module({
imports:[TypeOrmModule.forRootAsync({useClass:PostgresTypeormConfiguration})]
})
note: if you still got an error , you wrote one of the config option wrong in your .env file or you did not define .env file in your configModule

Deno Uncaught Error: No such host is known. (os error 11001)

I tried to connect the MongoDB Atlas to my Deno Application using https://deno.land/x/mongo#v0.21.2 framework. I tried the below code to run my application. but I get an error No such host is known. (os error 11001) What went wrong here
Error
error: Uncaught Error: No such host is known. (os error 11001)
at unwrapResponse (rt\10_dispatch_json.js:24:13)
at sendAsync (rt\10_dispatch_json.js:75:12)
at async Object.connect (rt\30_net.js:221:13)
at async MongoClient.connect (client.ts:41:14)
at async mongodb.ts:33:1
Mongodb.ts File
import { MongoClient } from "https://deno.land/x/mongo#v0.21.0/mod.ts";
const client1 = new MongoClient();
await client1.connect("mongodb+srv://user1:MYPASSWORD#cluster0.hmdnu.mongodb.net/TestingDB?retryWrites=true&w=majority");
const db = client1.database("TestingDB");
export default db;
I used this command to run my server
deno run --allow-net --allow-write --allow-read --allow-plugin --unstable server.ts
I fixed this using https://www.youtube.com/watch?v=hhdhydffKKE this video reference
Follow these steps to fix this
import { MongoClient } from "https://deno.land/x/mongo#v0.21.0/mod.ts";
const client1 = new MongoClient();
await client.connect({
db: "<db>",
tls: true,
servers: [
{
host: "<host>",
port: 27017,
},
],
credential: {
username: "<user>",
password: "<password>",
db: "<db>",
mechanism: "SCRAM-SHA-1",
},
});
const db = client1.database("TestingDB");
export default db;
This is not mentions in the document, but this will help to fix the issue
<db> is the database name, you can get the database name by following these steps
Step-1
Step-2
To find the <host> follow these steps
Step -1
Step -2
Step -3

How to find my database host address for CI / CD?

I'm going to conduct CI / CD in gitlab in AWS. My website contains a Postgresql database.
Question 1: But I don't know how to find the db host. Some say the host name is localhost, but I doubt it because I've deployed my website to AWS. Should it be elastic IP?
My .gitlab-ci.yml file is as follows:
image: node:latest
stages:
- testing
variables:
POSTGRES_DB: firstdb
POSTGRES_USER: johndoe
POSTGRES_PASSWORD: 1234
POSTGRES_HOST: //I don't know
testing:
services:
- postgres:latest
before_script:
- npm install -g yarn
- yarn install
- yarn knex migrate:latest --env testing
stage: testing
script:
- yarn jest
Question 2: Also, should I change the database config of development, testing and production of knex.ts accordingly, so that it aligns with .gitlab-ci.yml?
My knex file is as follows:
import * as dotenv from 'dotenv';
dotenv.config();
module.exports = {
development: {
client: 'postgresql',
connection: {
database: process.env.DB_NAME , //should I type actual data?
user: process.env.DB_USERNAME ,
password: process.env.DB_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},
testing:{
client: 'postgresql',
connection: {
host: process.env.POSTGRES_HOST ,//should I type actual data?
database: process.env.POSTGRES_DB ,
user: process.env.POSTGRES_USER ,
password: process.env.POSTGRES_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
},
production: {
client: "postgresql",
connection: {
database: process.env.DB_NAME ,//should I type actual data?
user: process.env.DB_USERNAME ,
password: process.env.DB_PASSWORD
},
pool: {
min: 2,
max: 10
},
migrations: {
tableName: "knex_migrations"
}
}
};
Many thanks in advance. :)
The hostname is postgres. the hostname is derived from the image name.
explained here:
https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#how-services-are-linked-to-the-job

Knex is not reading connection string from knexfile

I have been given a knexfile like this:
require('dotenv').config()
module.exports = {
client: 'pg',
connection: process.env.DB_CONNECTION,
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
};
The connection string I supply is:
Host=localhost;Database=heypay;Username=postgres;Password=1234
However, Knex keeps issuing the error:
password authentication failed for user "user"
Apparently, the username I have given is not user. Moreover, I have tried to hardcore the connection string into the connection filed under module.exports. This still ended up in vain.
The trick is, the connection property can either be a string or an object. That's why you were able to supply an environment variable (it's a string).
The reason your original string was failing is not a Knex problem: Postgres connection strings have a slightly different format. You can use a similar approach as your first attempt, but pay attention to the key names:
host=localhost port=5432 dbname=mydb connect_timeout=10
Also note spaces, not semicolons. However in my experience most people use a Postgres URI:
postgresql://[user[:password]#][netloc][:port][,...][/dbname][?param1=value1&...]
So in your example, you'd use:
module.exports = {
client: 'pg',
connection: 'postgresql://your_database_user:password#localhost/myapp_test',
pool: {
min: 2,
max: 10
},
migrations: {
tableName: 'knex_migrations'
}
};
I was using a .NET style connection string, the correct one would be in the following format:
{
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}

Save monolog in mongodb in symfony 4

I want to add monolog in mongodb with default handler(MongoDBHandler) in Symfony 4.
my monolog.yaml file in dev folder
monolog:
handlers:
mongo:
type: mongo
mongo:
id: monolog.logger.mongo
host: '%env(MONGODB_URL)%'
database: '%env(MONGODB_DB)%'
collection: logs
my services.yaml
services:
monolog.logger.mongo:
class: Monolog\Handler\MongoDBHandler
arguments: ['#doctrine_mongodb']
my doctrine_mongodb.yaml
doctrine_mongodb:
auto_generate_proxy_classes: '%kernel.debug%'
auto_generate_hydrator_classes: '%kernel.debug%'
connections:
default:
server: '%env(MONGODB_URL)%'
options:
db: '%env(MONGODB_DB)%'
log:
server: '%env(MONGODB_URL)%'
options:
db: '%env(MONGODB_DB)%'
connect: true
default_database: '%env(MONGODB_DB)%'
document_managers:
log:
auto_mapping: false
logging: false
But doesn't work.
one of the errors:
Cannot autowire service "monolog.logger.mongo": argument "$database"
of method "Monolog\Handler\MongoDBHandler::__construct()" is
type-hinted "string", you should configure its value explicitly.
While i use database option in monolog config.
Is there any document?
Another way to enable mongodb for monolog is:
monolog:
handlers:
mongo:
type: mongo
mongo:
host: '%env(MONGODB_URL)%'
user: myuser
pass: mypass
database: '%env(MONGODB_DB)%'
collection: logs
, So it mean you need to remove id field and add user and pass instead.
If you use doctrine mongodb already, it's possible to re-use it's connection, avoiding more ENV vars to separate the DSN:
monolog:
handlers:
mongo:
type: mongo
mongo:
id: "doctrine_mongodb.odm.default_connection"
database: "%env(MONGODB_DB)%"
collection: MyLogDocument # Keeping this the same, allows you to simply use a doctrine repository to access the documents in your app if needed
level: debug
I get the following error:
Attempted to load class "MongoClient" from the global namespace.
Did you forget a "use" statement?
protected function getMonolog_Handler_MongoService()
{
$this->privates['monolog.handler.mongo'] = $instance = new \Monolog\Handler\MongoDBHandler(new \MongoClient('mongodb://admin:pass#localhost:27017'), 'monolog', 'logs', 100, true);
$instance->pushProcessor(($this->privates['monolog.processor.psr_log_message'] ?? ($this->privates['monolog.processor.psr_log_message'] = new \Monolog\Processor\PsrLogMessageProcessor())));
return $instance;
}