Skip to content

Instantly share code, notes, and snippets.

View isccarrasco's full-sized avatar
🏠
Working from home

Mario Jiménez Carrasco isccarrasco

🏠
Working from home
View GitHub Profile
@isccarrasco
isccarrasco / autopgsqlbackup.sh
Last active November 13, 2024 03:48 — forked from matthewlehner/autopgsqlbackup
Script to automate the postgresql database backups, this script can create backups for daily, weekly and monthly for an only database or all databases, also can create crontab task for backups using hours of backups.
#!/bin/bash
#
# PostgreSQL Backup Script Ver 1.0
# http://autopgsqlbackup.frozenpc.net
# Copyright (c) 2005 Aaron Axelsen <[email protected]>
#
# This script is based of the AutoMySQLBackup Script Ver 2.2
# It can be found at http://sourceforge.net/projects/automysqlbackup/
#
# The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9
@isccarrasco
isccarrasco / Update PostgreSQL on Mac
Last active August 29, 2015 14:22 — forked from joho/gist:3735740
Update PostgreSQL on Mac
### Steps to upgrade/install and run PostgreSQL 9.4.3 using Homebrew (Mac OS X)
(if you aren't using version 9.3.5_1, change line 6 with the correct version)
1. launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
2. mv /usr/local/var/postgres /usr/local/var/postgres-9.3
3. brew update
4. brew upgrade postgresql
5. initdb /usr/local/var/postgres -E utf8
6. pg_upgrade -b /usr/local/Cellar/postgresql/9.3.5_1/bin -B /usr/local/Cellar/postgresql/9.4.3/bin -d /usr/local/var/postgres-9.3 -D /usr/local/var/postgres
@isccarrasco
isccarrasco / read-only-user.sql
Created July 10, 2015 03:15
Script for create a read-only user on PostgreSQL.
CREATE ROLE queryUser WITH NOCREATEDB NOCREATEROLE NOCREATEUSER NOINHERIT NOREPLICATION ENCRYPTED PASSWORD '****' CONNECTION LIMIT 1 LOGIN;
GRANT USAGE ON SCHEMA public TO queryUser;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO queryUser;
@isccarrasco
isccarrasco / disconnect-user-postgresql.md
Last active August 16, 2016 17:48
Disconnect User from a database on PostgreSQL.

SELECT pg_terminate_backend(pg_stat_activity.pid) FROM pg_stat_activity WHERE pg_stat_activity.datname = 'TARGET_DB' AND pid &lt;&gt; pg_backend_pid();

@isccarrasco
isccarrasco / restart-postgresql.md
Last active August 1, 2016 16:49
Command tu stop and start the PostgreSQL on Mac OS X

pg_ctl -D /usr/local/var/postgres stop -s -m fast

pg_ctl -D /usr/local/var/postgres/ -l /usr/local/var/postgres/server.log start

@isccarrasco
isccarrasco / change-tables-owner.md
Created October 3, 2015 00:17
Change tables owner for a postgresql schema.

for tbl in psql -qAt -c "select tablename from pg_tables where schemaname = 'public';" -h localhost -U postgres -d DATABASE ; do psql -c "alter table "$tbl" owner to ROLE" -h localhost -U postgres -d DATABASE ; done

@isccarrasco
isccarrasco / mdb2postgres.sh
Last active September 11, 2024 16:59 — forked from mutolisp/mdb2postgres.sh
Convert Microsoft Access *.mdb file into PostgreSQL database
#!/usr/bin/env bash
# install mdbtools first!
# mdbtools: https://github.com/brianb/mdbtools
# ref: https://wiki.postgresql.org/wiki/Converting_from_other_Databases_to_PostgreSQL
DBMS=postgres
for MDB in `ls | grep .mdb$`
@isccarrasco
isccarrasco / migrate-postgis.sh
Last active February 24, 2016 21:21
Script that help to migrate a postgis database from an older versión (<= 9.3) to a new version ( >= 9.4) running on Mac OS X.
#!/bin/bash
# Script to migrate postgis
# Backup database
pg_dump -h localhost -p 5432 -U postgres -Fc -b -v -f "olddb.backup" db-name
# Create database
psql -c -U postgres "CREATE DATABASE db-name;"
# Apply postgis complements to the new database
@isccarrasco
isccarrasco / wildfly-install.sh
Last active October 6, 2018 05:50 — forked from sukharevd/wildfly-install.sh
Script to install JBoss Wildfly 11.x as service in Linux
#!/bin/bash
#title :wildfly-install.sh
#description :The script to install Wildfly 10.x
#more :http://sukharevd.net/wildfly-8-installation.html
#author :Dmitriy Sukharev
#date :2015-10-24T17:14-0700
#usage :/bin/bash wildfly-install.sh
#tested-version :10.0.0.Final
#tested-distros :Debian 7,8; Ubuntu 15.10; CentOS 7; Fedora 22
@isccarrasco
isccarrasco / reinstall_mac.md
Last active July 20, 2023 23:47
Reinstallation of Mac

Configure MacBook Pro for work

This gist was created based on this web page.

  1. Download Xcode by executing xcode-select --install and select Get Xcode option.

  2. Install the standalone Command Line Tools by executing xcode-select --install and select Install option.

  3. Install Homebrew by executing the next command.