¿Cuánto tiempo debe ESTABLECER LA INSTANTÁNEA DE LECTURA CONFIRMADA EN LA toma?


Cuánto tiempo debería tomar para ejecutarse

ALTER DATABASE [MySite] SET READ_COMMITTED_SNAPSHOT ON

Acabo de ejecutarlo y ha tomado 10 minutos.

¿Cómo puedo comprobar si se aplica?

Author: Simon_Weaver, 2008-10-24

8 answers

Puede comprobar el estado de la configuración READ_COMMITTED_SNAPSHOT utilizando el sys.databases vista. Compruebe el valor de la is_read_committed_snapshot_on columna. Yapreguntado y respondido .

En cuanto a la duración, Books Online indica que no puede haber otras conexiones a la base de datos cuando esto tenga lugar, pero no requiere el modo de usuario único. Así que puede ser bloqueado por otras conexiones activas. Ejecutar sp_who (o sp_who2) a ver qué más está conectado a la base.

 58
Author: Rick,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 12:09:37

Prueba esto:

ALTER DATABASE generic SET READ_COMMITTED_SNAPSHOT ON WITH ROLLBACK IMMEDIATE
 38
Author: Hosam Aly,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-08-10 07:02:38

OK (yo soy el interrogador original) así que resulta que todo este tiempo ni siquiera tenía la maldita cosa habilitada.

Aquí está el código final a ejecutar para habilitar el modo de instantánea y asegurarse de que esté habilitado.

SELECT is_read_committed_snapshot_on, snapshot_isolation_state_desc,snapshot_isolation_state FROM sys.databases WHERE name='shipperdb'

ALTER DATABASE shipperdb SET allow_snapshot_isolation ON
ALTER DATABASE shipperdb SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE shipperdb SET read_committed_snapshot ON
ALTER DATABASE shipperdb SET MULTI_USER

SELECT is_read_committed_snapshot_on, snapshot_isolation_state_desc,snapshot_isolation_state FROM sys.databases WHERE name='shipperdb'

Esto funciona incluso con conexiones activas (presumiblemente estás bien con ellas siendo expulsadas).

Puede ver el estado antes y después y esto debería ejecutarse casi inmediatamente.


IMPORTANTE:

La opción READ_COMMITTED_SNAPSHOT anterior corresponde a IsolationLevel.ReadCommitted in. NET
La opción ALLOW_SNAPSHOT_ISOLATION anterior corresponde a IsolationLevel.Instantánea en. NET

Gran artículo sobre diferentes versiones


Consejos. NET:

Parece que Isolationlevel.ReadCommitted está permitido en el código incluso si no está habilitado por la base de datos. No se lanza ninguna advertencia. Así que hágase un favor y asegúrese de que está encendido antes de asumir que es por 3 años como yo ¡lo hice!!!

Si estás usando C# probablemente quieras el ReadCommitted IsolationLevel y no Snapshot - a menos que estés haciendo escrituras en esta transacción.

READ COMMITTED SNAPSHOT hace lecturas optimistas y escribe pesimistas. En contraste, SNAPSHOT hace lecturas optimistas y escribe optimistas. (de aquí)

bool snapshotEnabled = true;

using (var t = new TransactionScope(TransactionScopeOption.Required,
               new TransactionOptions
{
     IsolationLevel = IsolationLevel.ReadCommitted
}))
{
     using (var shipDB = new ShipperDBDataContext())
     {

     }
}

Además, puede obtener un error sobre "no se puede promover" una transacción. Busca 'promoción' en Introduciendo el sistema.Transacciones en. NET Framework 2.0.

A menos que esté haciendo algo especial como conectarse a una base de datos externa (o segunda base de datos), entonces algo tan simple como crear un nuevo DataContext puede causar esto. Tenía un caché que 'giraba' su propio datacontext en la inicialización y esto estaba tratando de escalar la transacción a una distribuida completa.

La solución era simple:

        using (var tran = new TransactionScope(TransactionScopeOption.Suppress))
        {
            using (var shipDB = new ShipperDBDataContext())
            { 
                 // initialize cache
            }
        }

Véase también Deadlocked artículo de @ CodingHorror

 24
Author: Simon_Weaver,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-05-23 11:46:56

Prueba este código:

if(charindex('Microsoft SQL Server 2005',@@version) > 0)
begin
    declare @sql varchar(8000)
    select @sql = '
    ALTER DATABASE ' + DB_NAME() + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE ;
    ALTER DATABASE ' + DB_NAME() + ' SET READ_COMMITTED_SNAPSHOT ON;
    ALTER DATABASE ' + DB_NAME() + ' SET MULTI_USER;'

    Exec(@sql)
end
 8
Author: Nick Berardi,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-01-13 16:26:13

Intente usar la base de datos maestra antes de alterar la base de datos actual.

USE Master
GO

ALTER DATABASE [YourDatabase] SET READ_COMMITTED_SNAPSHOT ON
GO
 2
Author: eLVik,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-10 12:43:23

No me tomé un segundo cuando cambié mi base de datos a usuario único

 2
Author: Yasin Kilicdere,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-12 11:41:21

Probé el comando:

ALTER DATABASE MyDB SET READ_COMMITTED_SNAPSHOT ON
GO

Contra una caja de desarrollo, pero el tomó más de 10 minutos y así lo maté.

Entonces encontré esto:

Https://willwarren.com/2015/10/12/sql-server-read-committed-snapshot /

Y usó su bloque de código (que tomó alrededor de 1:26 para ejecutarse):

USE master
GO

/** 
 * Cut off live connections
 * This will roll back any open transactions after 30 seconds and
 * restricts access to the DB to logins with sysadmin, dbcreator or
 * db_owner roles
 */
ALTER DATABASE MyDB SET RESTRICTED_USER WITH ROLLBACK AFTER 30 SECONDS
GO

-- Enable RCSI for MyDB
ALTER DATABASE MyDB SET READ_COMMITTED_SNAPSHOT ON
GO

-- Allow connections to be established once again
ALTER DATABASE MyDB SET MULTI_USER
GO

-- Check the status afterwards to make sure it worked
SELECT is_read_committed_snapshot_on
FROM sys.databases
WHERE [name] = 'MyDB '
 2
Author: Jeff Mergler,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-08-09 19:45:04

Intente apagar los otros servicios SQL para que solo se ejecute el servicio SQL server.

El mío duró 5 minutos y luego lo cancelé porque era obvio que no estaba pasando nada. Es un nuevo servidor por lo que no hay otros usuarios conectados. Apagué los servicios de informes SQL y luego lo volví a ejecutar.. tardó menos de un segundo en completarse.

 0
Author: Jeff,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-28 18:59:00