Ok

En poursuivant votre navigation sur ce site, vous acceptez l'utilisation de cookies. Ces derniers assurent le bon fonctionnement de nos services. En savoir plus.

  • MAJ Sequence

    sqlplus -s user_admin/<mdp>@BDDREC << EOF > upd_seq.sql
    SELECT 'SELECT setval('''||sequence_name||''','||last_number||', true);'
    FROM user_sequences;
    exit;
    EOF
    psql --single-transaction  -h $2 -U postgres -d $1 -f ./upd_seq.sql

  • [MSSQL] Disable/Enable FK

    disable FK

    DECLARE @sql NVARCHAR(MAX) = N'';

    ;WITH x AS 
    (
      SELECT DISTINCT obj = 
          QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.' 
        + QUOTENAME(OBJECT_NAME(parent_object_id)) 
      FROM sys.foreign_keys
    )
    SELECT @sql += N'ALTER TABLE ' + obj + ' NOCHECK CONSTRAINT ALL;
    ' FROM x;

    EXEC sp_executesql @sql;

    enable FK 

    DECLARE @sql NVARCHAR(MAX) = N'';

    ;WITH x AS 
    (
      SELECT DISTINCT obj = 
          QUOTENAME(OBJECT_SCHEMA_NAME(parent_object_id)) + '.' 
        + QUOTENAME(OBJECT_NAME(parent_object_id)) 
      FROM sys.foreign_keys
    )
    SELECT @sql += N'ALTER TABLE ' + obj + ' WITH CHECK CHECK CONSTRAINT ALL;
    ' FROM x;

    EXEC sp_executesql @sql;

  • Calcul stats PostgreSQL

    for tablename in $(psql -U postgres -h $2 -d $1 -t -c "select table_name as _table from information_schema.tables t where t.table_schema='sche_admin' order by _table asc"); do

      echo $tablename

      psql -U postgres -h $2 -d $1 -c "analyze ${tablename};"

      psql -U postgres -h $2 -d $1 -c "select count(*) ${tablename} from ${tablename};" >> compte_pgsql.log

    done

     

    En // :

    vacuumdb --port=$PORT --username=$PG_USER --analyze-only --verbose --jobs=4  $PG_DATABASE